Spring Kafka 模板实现示例,用于查找偏移量、确认 [英] Spring Kafka Template implementaion example for seek offset, acknowledgement

查看:31
本文介绍了Spring Kafka 模板实现示例,用于查找偏移量、确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 spring-kafka-template 的新手.我尝试了一些基本的东西,它们工作正常.但我正在尝试实施 Spring 文档 喜欢:

I am new to spring-kafka-template. I tried some basic stuff in it and they are working fine. But I am trying to implement some concepts mentioned at Spring Docs like :

  1. 偏移寻求
  2. 感谢听众

我试图通过网络找到一些例子,但没有成功.我唯一找到的是它的源代码.

I tried to find some example for it over net but was unsuccessful. The thing only I found is its source code.

我们有一个与这篇文章中提到的相同的问题 Spring kafka 消费者,寻求运行时偏移.

We have a same issue as mentioned in this post Spring kafka consumer, seek offset at runtime.

但是没有可用的示例来实现相同的功能.

But there is no example available to implement the same.

有人可以举例说明如何实施它们吗?

Can someone give any example on how to implement them?

提前致谢.

推荐答案

你应该使用 ConsumerSeekAware 来处理搜索:

You should use ConsumerSeekAware for that purpose to deal with seeks:

static class Listener implements ConsumerSeekAware {

     private final ThreadLocal<ConsumerSeekCallback> seekCallBack = new ThreadLocal<>();

     public void registerSeekCallback(ConsumerSeekCallback callback) {
        this.seekCallBack.set(callback);
    }

@KafkaListener(...)
        public void listen(@Payload String foo,
                Acknowledgment ack) {

                this.seekCallBack.get().seek(topic, partition, 0);
            }
        }

}

这篇关于Spring Kafka 模板实现示例,用于查找偏移量、确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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