Kamil Mikolajczyk
Kamil Mikolajczyk

Reputation: 911

Spring Kafka doesn't autocreate topics

I'm using spring-kafka and I want it to auto create my topics on startup. I've configured it by adding @Bean NewTopic in my configuration class. This however doesn't seem to execute because earlier, from what I see in logs, NetworkClient from apache-kafka is "Sending METADATA request", then the response says:

topics=[MetadataResponseTopic(errorCode=3 and Error while fetching metadata with correlation id 2 : {my.topic.name=UNKNOWN_TOPIC_OR_PARTITION}

then this repeats for 60 seconds (max.block.ms) and finally stops the whole app, because Spring fails to initialize all the beans, because of this missing topic. It seems that NewTopic bean doesn't get a chance to be called and do its job.

Anyone knows what's wrong?

Can I in any way control order of execution of things here, so that NewTopic is called (and actual topic created) when spring initializes beans but before any of them starts doing their job (trying to send something to that not-yet existing topic)

Upvotes: 0

Views: 1114

Answers (1)

Kamil Mikolajczyk
Kamil Mikolajczyk

Reputation: 911

So, as @Artem suggested, the problem was that one of my Spring beans during initialization was already executing some code which involved interaction with Kafka, hence - spring didn't fully initialize beans because it crashed before NewTopic was used

Upvotes: 1

Related Questions