Reputation: 41
I did autoStartup(false)
on the container factory but not sure where I should inject KafkaListenerEndpointRegistry
.
I don't want consumer to connect at the time of build. It should connect Kafka
topic after spring boot application start completely.
Upvotes: 4
Views: 12910
Reputation: 39998
You should inject the KafkaListenerEndpointRegistry
in class with KafkaListener
annotated method because from the docs
The listener containers created for @KafkaListener annotations are not beans in the application context. Instead, they are registered with an infrastructure bean of type KafkaListenerEndpointRegistry
so by using this KafkaListenerEndpointRegistry
instance you can manage the life cycle of containers start/stop here
Example :
@Autowired
private KafkaListenerEndpointRegistry registry;
...
@KafkaListener(id = "myContainer", topics = "myTopic", autoStartup = "false")
public void listen(...) { ... }
...
registry.getListenerContainer("myContainer").start();
Upvotes: 5