Kafka Consumer 配置 - auto.offset.reset 如何控制消息消费 [英] Kafka Consumer configuration - How does auto.offset.reset controls the message consumption
问题描述
我想了解,ConsumerConfig.auto.offset.reset = latest 如何影响消息消费.
I'm trying to understand, how does the ConsumerConfig.auto.offset.reset = latest would affect the message consumption.
例如我有一个消费者,最初在时间 t1 发送 100 条消息,然后我的消费者在 t1+30 秒启动并运行,那么我的消费者会消费 t1+30 秒后发布的消息还是会消费消息从 t1 开始发布?
For example I've a consumer, sending 100 messages initially at time t1 and then my consumer is up and running at t1+30 sec, then would my consumer consume the messages published after t1+30 sec or will it consume messages published t1 onwards?
推荐答案
视情况而定.
auto.offset.reset
仅在消费者组没有存储偏移量时适用.
auto.offset.reset
only applies when there is no stored offset for the consumer group.
适用于以下情况:
- 消费者组第一次消费
- 如果消费者没有提交任何偏移量,则下次启动时
- 如果消费者组已过期(现代代理默认为 7 天)
- 如果存储的偏移量指向的消息由于消息保留策略而被删除(尝试读取已清除的消息会触发规则的应用)
如果消费者提交了一个偏移量;下次启动时,它将从最后提交的偏移量开始.
If a consumer commits an offset; it will start at the last committed offset the next time it is started.
这篇关于Kafka Consumer 配置 - auto.offset.reset 如何控制消息消费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!