Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kafka: disable create topic from Java

Using Kafka with the Java lib, I want to disable the automatic creation of topic (if it doesn't already exist).

Some sites says I should put auto.create.topics.enable to false, but this is not recognized in Java.

15:11:56.962 [main] WARN  o.a.k.c.consumer.ConsumerConfig -  The configuration 'auto.create.topics.enable' was supplied but isn't a known config.

Currently I put it in my docker-compose as environment variable:

KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'

This works, but I'd like to manag it from Java by user.

Is this possible?

like image 773
Rolintocour Avatar asked Jun 22 '26 16:06

Rolintocour


2 Answers

It is Broker level config. You can't let user manage this from the java client programs.

As auto.create.topics.enable property is read-only broker configuration, which requires the kafka services to be restarted. Hence it is not possible to handle it from client side.

You can read the configurations here with the dynamic update mode : https://kafka.apache.org/documentation/#brokerconfigs

like image 113
Nishu Tayal Avatar answered Jun 25 '26 18:06

Nishu Tayal


Spring has the spring.cloud.stream.kafka.binder.autoCreateTopics property that defaults to true and works independently of the Broker property auto.create.topics.enable. I'm guessing it's only effective if your Broker config allows clients to create topics. It's probably safer to block that permission than to rely on clients to behave.

https://cloud.spring.io/spring-cloud-stream-binder-kafka/spring-cloud-stream-binder-kafka.html

like image 32
KC Baltz Avatar answered Jun 25 '26 20:06

KC Baltz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!