春季Kafka消费者,倒退消费者抵销以返回"n"记录 [英] Spring Kafka Consumer, rewind consumer offset to go back 'n' records

查看:168
本文介绍了春季Kafka消费者,倒退消费者抵销以返回"n"记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用编程"方式,使用org.springframework.kafka.listener.ConcurrentMessageListenerContainer

I'm using "programmatic" way of consuming messages from Kafka topic using org.springframework.kafka.listener.ConcurrentMessageListenerContainer

我想知道是否存在一种春季"的方式来回绕主题的特定分区的偏移量以返回"n"个消息?

I'm wondering if there's a "spring" way of rewinding offsets for a specific partitions of a topic to go back 'n' messages?

想知道最干净的方法(以编程方式而不是使用CLI).

Would like to know the cleanest way of doing this (programmatically and not using the CLI).

推荐答案

如果要在应用程序启动期间重置偏移量,请使用ConsumerAwareRebalanceListener并在分配分区时对使用者执行查找.您可以通过调用Consumer.position()来找到当前偏移量.

If you want to reset the offsets during application startup, use a ConsumerAwareRebalanceListener and perform the seeks on the consumer when the partitions are assigned; you can find the current offset(s) by calling Consumer.position().

如果要在运行时任意倒退分区,请让侦听器实现ConsumerSeekAware并获取对ConsumerSeekCallback的引用.

If you want to arbitrarily rewind the partitions at runtime, have your listener implement ConsumerSeekAware and grab a reference to the ConsumerSeekCallback.

有关使用ConsumerSeekAware的示例,请参见此答案.

See this answer for an example of using ConsumerSeekAware.

ConsumerSeekAware也具有onIdleContainer(),当在idleEventInterval期间未接收到任何记录时,将调用它.该回调为您提供了当前的偏移量.

ConsumerSeekAware also has onIdleContainer() which will be called when no records have been received during idleEventInterval; that callback provides you with the current offsets.

这篇关于春季Kafka消费者,倒退消费者抵销以返回"n"记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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