如何使用 Spring Kafka 检查 Kafka 是否为空? [英] How to check if Kafka is empty using Spring Kafka?
问题描述
当我重新启动我的应用程序时,我需要处理 Kafka 中剩余的消息,直到它为空,然后我的应用程序应该继续正常工作.我的问题是如何检查 Kafka 主题是否为空.我正在使用 Spring Kafka.
When I restart my application I need to process the remaining messages in Kafka until it's empty and then my application should continue to work normally. My problem is how to check if a Kafka topic is empty. I am using Spring Kafka.
推荐答案
您可以简单地向具有唯一标识符或特殊类型(例如 type: RESTART
)的主题发送特殊的重启"消息并配置您的 Kafka 侦听器以在收到重启"消息时通知您的应用程序(例如,通过单独的 Kafka 主题).
You could simply send a special "restart" message to the topic with a unique identifier or special type (e.g. type: RESTART
) and configure your Kafka Listener to notify your application (e.g. via a separate Kafka topic) when the "restart" message is received.
这篇关于如何使用 Spring Kafka 检查 Kafka 是否为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!