问题
I have a requirement where I want to start Kakfa consumer manually.
Code :
class Dummy implements
ConsumerSeekAware
{
@Autowired
KafkaListenerEndpointRegistry registry;
CountDownLatch latch;
@Autowired
ConcurrentKafkaListenerContainerFactory factory;
onIdleEvent(){
latch.countdown()
}
@KafkaListener(id="myContainer",
topics="mytopic",
autoStartup="false")
public void listen() {}
@Scheduled(cron=" some time ")
void do_some_consumption(){
latch = new CountDownLatch(1);
this.registry.getListenerContainer("myContainer").start();
latch.await();
do processing
this.registry.getListenerContainer("myContainer").stop()
}
}
I have made the bean of ConcurrentKafkaListenerContainerFactory with all props in my other Config class which I am Autowiring here.
However, I get a null pointer exception when I start my container using this.registry.getListenerContainer("myContainer").start()
来源:https://stackoverflow.com/questions/62412316/kafkaendpointlistenerregistry-start-throws-null-pointer-exception