Kafka 没有向消费者发送足够的消息

Kafka not sending enough messages to consumer

我有一个 kafka 主题,3 个分区,只有一个消费者有批次。我在消费者端使用 spring kafka 并具有以下消费者道具:

max.poll.records=10000
fetch.min.bytes=2000000
fetch.max.bytes=15000000
fetch.max.wait.ms=1000
max.poll.interval.ms=300000
auto.offset.reset.config=earliest
idle.event.interval=120000

即使队列中有数千条消息(GB 数据)在等待,kafka 消费者在每次轮询时也会收到大约 10 条消息(总大小约为 1MB)。消费者应该获取 fetch.max.bytes(在我的 prop ~15MB)或 max.poll.records(在我的例子中是 10000)的批次。有什么问题吗?

有几种情况可能会导致此问题,请进行以下更改:

  1. 增加 fetch.min.bytes- 消费者也可以分批获取 fetch.min.bytes,即 1.9MB。
  2. 增加fetch.max.wait.ms-轮询函数等待fetch.min.bytesfetch.max.wait.ms触发,先到先得。
    fetch.max.wait.ms 在您的配置中是 1 秒,听起来不错,但增加它以防出现问题。
  3. 增加 max.partition.fetch.bytes- 默认为 1MB,它可以减少像您这样的小分区主题的轮询大小(对于 3 个分区主题,限制最多 3MB 轮询单一消费者)。

尝试使用这些值:

fetch.min.bytes=12000000
fetch.max.wait.ms=5000  
max.partition.fetch.bytes=5000000  

更深入的解释:
https://www.oreilly.com/library/view/kafka-the-definitive/9781491936153/ch04.html