Spring Kafka-在运行时订阅新主题 [英] Spring Kafka - Subscribe new topics during runtime

查看:56
本文介绍了Spring Kafka-在运行时订阅新主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用注释 @KafkaListener 在我的应用程序中使用主题.我的问题是,如果我在kafka中创建了一个新主题,但是我的使用者已经在运行,那么即使该使用者与我正在使用的 topicPattern 相匹配,看来该使用者也不会选择该新主题.有没有一种方法可以定期刷新"已订阅的主题,以便在我的运行中的消费者身上获得新的主题并重新平衡?

I'm using the annotation @KafkaListener to consume topics on my application. My issue is that if I create a new topic in kafka but my consumer is already running, it seems the consumer will not pick up the new topic, even if it matches with the topicPattern I'm using. Is there a way to "refresh" the subscribed topics periodically, so that new topics are picked up and rebalanced upon my running consumers?

我正在使用Spring Kafka 1.2.2和Kafka 0.10.2.0.

I'm using Spring Kafka 1.2.2 with Kafka 0.10.2.0.

致谢

推荐答案

您无法在运行时动态添加主题.您必须停止/启动容器才能开始收听新主题.

You can't dynamically add topics at runtime; you have to stop/start the container to start listening to new topics.

您可以 @Autowire KafkaListenerEndpointRegistry ,并通过 id 停止/启动侦听器.

You can @Autowire the KafkaListenerEndpointRegistry and stop/start listeners by id.

您还可以通过在注册表本身上调用 stop()/ start()来停止/启动所有侦听器.

You can also stop/start all listeners by calling stop()/start() on the registry itself.

这篇关于Spring Kafka-在运行时订阅新主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆