How to pass topics dynamically to a kafka listener?

匿名 (未验证) 提交于 2019-12-03 00:44:02

问题:

From a couple of days I'm trying out ways to dynamically pass topics to Kafka listener rather than using them through keys from a Java DSL. Anyone around done this before or could throw some light on what is the best way to achieve this?

回答1:

You cannot "dynamically pass topics to Kafka listener "; you have to programmatically create a listener container instead.



回答2:

you can change Topics at runtime dynamicly!!!!

@Component public class StoppingErrorHandler implements ErrorHandler {      @Autowired     private KafkaListenerEndpointRegistry kafkaListenerEndpointRegistry;      @Override     public void handle(Exception thrownException, ConsumerRecord<?, ?> record) {         ConcurrentMessageListenerContainer listenerContainer = (ConcurrentMessageListenerContainer)kafkaListenerEndpointRegistry.getListenerContainer("fence");         ContainerProperties cp=listenerContainer.getContainerProperties();         String[] topics =cp.getTopics();         topics[0]="gaonb";         listenerContainer.stop();         listenerContainer.start();     } } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!