Java Kafka Client Dynamic Sasl Jaas config update

Viewed 21

Is there way to dynamically update Java client Kafka producers sasl jaas config without stopping/recreating client each time of Jaas config update?

1 Answers

Generally, Jaas config has a template that looks like org.apache.kafka.common.security.scram.ScramLoginModule required username="%s" password="%s"; , which is used for authentication. If, for example, Kafka cluster administrator change password of the user it won't be disconnected automatically, after some time you'll get an error and session will be terminated. You can something like

try{
      final Consumer<Long, String> consumer = new KafkaConsumer<>(props);
      consumer.subscribe(Collections.singletonList(TOPIC));
} catch (KafkaException ke){
    // here comes code that restarts consumer
}

But, whenever the use-case, changing this configuration would require client re-authorization, that would disrupt consumption/producing of records.

Related