Kafka Consumer与enable.auto.commit = false仍在提交偏移量

时间:2020-05-19 07:42:39

标签: spring-kafka

Kafka使用者已经处理了消息1,2,3,4,并且enable.auto.commit设置为false。

但是在重新启动使用者时,它不会再次处理以上消息,从CLI中我可以看到偏移量已经增加,并且没有滞后(因此提交)。

请帮助您,以了解尽管属性enable.auto.commit设置为false,消费者仍如何提交偏移量。

下面是消费者属性

allow.auto.create.topics = true
auto.commit.interval.ms = 0
auto.offset.reset = latest
bootstrap.servers = [localhost:9092]
enable.auto.commit = false
fetch.max.bytes = 52428800
fetch.max.wait.ms = 500
fetch.min.bytes = 1
group.id = EmployeeConsumer

当前使用spring-kafka-2.5.0.RELEASE.jar作为依赖项

1 个答案:

答案 0 :(得分:2)

您需要显示您的Spring配置。

enable.auto.commit=false告诉kafka客户端不要提交偏移,但是Spring默认会提交偏移。

将侦听器容器的ackMode属性设置为AckMode.MANUAL,以禁用容器提交。

此外:

auto.offset.reset = latest意味着从未从未提交过补偿的消费者将从主题/分区的当前结尾开始消费,因此不会获取现有记录。