Spring Kafka Template implementaion example for seek offset, acknowledgement

假装没事ソ 提交于 2020-01-01 20:49:32

问题


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. Offset Seeking
  2. Acknowledging listeners

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

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?

Thanks in advance.


回答1:


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);
            }
        }

}


来源:https://stackoverflow.com/questions/44561341/spring-kafka-template-implementaion-example-for-seek-offset-acknowledgement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!