rookie
rookie

Reputation: 426

Make Kafka Consumer wait for Events

I have a use case where a consumer needs to listen to some events on a topic T1(consumesmessages in topic T1 and search for certain cases) .Only if it detect certain events then start consuming from topic T2 and work on the messages retrieved from T2.We are using spring kafka 2.1.7.I do not see a way to do this now as consumer would start reading from T2 as the kafkalistener bean for it comes up .I am looking for suggestions on how this can be achieved.

Upvotes: 1

Views: 3740

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121202

Each of your @KafkaListener should rely on slightly different ConcurrentKafkaListenerContainerFactory instances where one for the topic T2 should be configured with the setAutoStartup(false).

So, when condition in the @KafkaListener for T1 is met, you call a KafkaListenerEndpointRegistry.getListenerContainer(containerId).start() for the second @KafkaLisnter. The containerId comes from the @KafkaLisnter.id().

Upvotes: 1

Related Questions