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

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

问题描述

我是 spring-kafka-template 的新手.我尝试了一些基本的东西,他们工作正常.但是我正在尝试实现

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.

我们有与此帖子中提到的问题相同的问题春季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 来处理搜索:

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 Template实现示例,用于查找偏移量,确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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