Why does kafka initially take bootstrap servers from KafkaAdminClient?

Advertisements

this is not an issue. I’m just curious about the behavior and thats why i’m posting this.

I’m using Spring kafka with consumerFactory and producerFactory beans. I know that i can use spring auto configuration. But i went with this approach. In this approach, i’m using dead letter topic as error handler.

@RetryableTopic(
        attempts = "sample-topic",
        backoff = @Backoff(delay = 1000, multiplier = 3.0),
        autoCreateTopics = "false")

Above is the way i have added the dlt related configs. But i noticed one thing. When i use autoCreateTopics = "true" and when i start the application, it first try to capture configurations from KafkaAdminClient. When app starts, it first try to use the bootstrap servers defined in KafkaAdminClient which is 127.0.0.1 (Found this by looking at the ConsumerConfig values log printed initially when the app starts). Since i’m using a bootstrap server in MSK, when kafka try to connect to localhost, it gives disconnect error and only after few seconds, it will log the ConsumerConfig values (in that values, i can see the correct bootstrap server) and then it connect to my bootstrap server.

But if i add autoCreateTopics = "false", it will not try to connect to the bootstrap servers. It connect to the correct bootstrap server from the first try.

Can someone please explain this behavior ? Am i doing anything wrong, have i missed anything or is this the correct behavior ?

Thank you in advance…

>Solution :

Boot auto configures a KafkaAdmin which is used to provision the topics (if they don’t already exist).

It uses spring.kafka.bootstrap.servers (https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.kafka.bootstrap-servers) to create that admin. It is localhost:9092 by default.

So, either set that property, or create your own KafkaAdmin @Bean which will prevent Boot from configuring the default one.

Leave a ReplyCancel reply