首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >spring-cloud-stream-binder-kafka手动设置消费者偏移量

spring-cloud-stream-binder-kafka手动设置消费者偏移量
EN

Stack Overflow用户
提问于 2021-09-15 13:36:06
回答 1查看 69关注 0票数 0

在这里,在消费和处理kafka消息时,我们正在做一些redis operations.Whenever,redis关闭或抛出一个错误/异常,我们需要持久化偏移,当redis出现时,我们需要消费持久化偏移量中的消息。

EN

回答 1

Stack Overflow用户

发布于 2021-09-15 15:01:10

添加一个KafkaBindingRebalanceListener bean。

https://docs.spring.io/spring-cloud-stream-binder-kafka/docs/3.1.3/reference/html/spring-cloud-stream-binder-kafka.html#rebalance-listener

应用程序可能希望在最初分配分区时寻找任意偏移量的主题/分区,或者在使用者上执行其他操作。从2.1版开始,如果您在应用程序上下文中提供单个KafkaBindingRebalanceListener bean,它将连接到所有Kafka使用者绑定中。

代码语言:javascript
运行
复制
public interface KafkaBindingRebalanceListener {

...
    /**
     * Invoked when partitions are initially assigned or after a rebalance.
     * Applications might only want to perform seek operations on an initial assignment.
     * @param bindingName the name of the binding.
     * @param consumer the consumer.
     * @param partitions the partitions.
     * @param initial true if this is the initial assignment.
     */
    default void onPartitionsAssigned(String bindingName, Consumer<?, ?> consumer, Collection<TopicPartition> partitions,
            boolean initial) {

    }
}

在redis关闭时停止绑定,并在它恢复时重新启动它,并在Consumer上执行查找。

有关停止/启动绑定的信息,请参阅https://docs.spring.io/spring-cloud-stream/docs/3.1.3/reference/html/spring-cloud-stream.html#binding_visualization_control

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69194244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档