How to use Spring Kafka's Acknowledgement.acknowledge() method for manual commit

后端 未结 2 1292
北荒
北荒 2021-02-06 03:04

I am using Spring Kafka first time and I am not able to use Acknowledgement.acknowledge() method for manual commit in my consumer code as mentioned here https://docs.spring.io/s

2条回答
  •  灰色年华
    2021-02-06 03:42

    You really should follow documentation:

    When using manual AckMode, the listener can also be provided with the Acknowledgment; this example also shows how to use a different container factory.

    @KafkaListener(id = "baz", topics = "myTopic",
              containerFactory = "kafkaManualAckListenerContainerFactory")
    public void listen(String data, Acknowledgment ack) {
        ...
        ack.acknowledge();
    }
    

    There is really nowhere noted that Acknowledgment is a bean. So, change your receive() @KafkaListener method signature appropriately and remove that @Autowired for suspicious Acknowledgment bean - it just doesn't exists because this object is a part (header) of each received message.

提交回复
热议问题