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(); } }