我们有特定的主题,仅当条件consumpedEnabled = true时才需要使用消息。
因此,它应该像这样工作:
如果应用程序正在启动并且consumpedEnabled = true,则分配
划分给消费者,并消费来自主题的消息。
如果应用程序正在启动并且consumpedEnabled = false,则不要将分区分配给使用者,也不要消耗主题中的消息。
如果应用程序已经运行时使用了enableEnabled = false,但是在运行时属性变成了consumpedEnabled = true,则在运行时将分区分配给使用者并使用主题中的消息。
应用正在消耗消息但随后的情况enableEnabled变为false的情况无需考虑。
请帮助定义使用Spring Kafka和/或Kafka Java客户端实施决策的最佳方法
最佳答案
如果您使用的是@KafkaListener
@KafkaListener(id = "foo", ... , autoStartup="${consume.enabled}")
其中
consume.enabled
是属性。要在运行时启动/停止容器,请使用
KafkaListenerEndpointRegistry
bean。registry.getListenerContainer("foo").start();