使用 KafkaListener 时,如何检查主题消息是否已读到底? [英] When using KafkaListener, how can I check that a topic message has been read to the end?
本文介绍了使用 KafkaListener 时,如何检查主题消息是否已读到底?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在使用@KafkaListener 时,如何检查主题消息是否已读到最后?
When using @KafkaListener, how can I check that a topic message has been read to the end?
推荐答案
参见 这个答案 关于在没有更多记录可供读取时获取事件通知.
See this answer about getting an event notification when there are no more records to read.
可以使用事件中的Consumer
获取当前的position()
,以及endOffsets()
;下面显示了如何获取结束偏移量:
You can use the Consumer
in the event to get the current position()
, and endOffsets()
; the following shows how to get the end offsets:
@EventListener
void listen(ListenerContainerIdleEvent event) {
System.out.println(event);
try {
System.out.println(event.getConsumer().assignment());
System.out.println(event.getConsumer().endOffsets(event.getConsumer().assignment(), Duration.ofSeconds(5)));
}
catch (Exception e) {
e.printStackTrace();
}
}
这篇关于使用 KafkaListener 时,如何检查主题消息是否已读到底?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文