1 Star 1 Fork 0

zzz9h/modern-cpp-kafka

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
GoodPracticesToUseKafkaConsumer.md 995 Bytes
一键复制 编辑 原始数据 按行查看 历史
Kenneth Jia 提交于 5年前 . Initial Commit

Good Practices to Use a KafkaConsumer

If we want to achieve high performance/availability, here're some rules of thumb.

How to distribute the messages (for the same topics) to different KafkaConsumers

  • Use a consumer group for these KafkaConsumers, thus they will work together -- each one deals with different partitions.

  • Besides subscribe (topics), users could also choose to explicitly assign certain partitions to a KafkaConsumer.

How to enhance the throughput

  • Try with a larger QUEUED_MIN_MESSAGES, especially for small messages.

  • Use multiple KafkaConsumers to distribute the payload.

How to avoid polling duplicated messages

  • A KafkaManualCommitConsumer could help to commit the offsets more frequently (e.g, always do commit after finishing processing a message).

  • Don't use quite a large MAX_POLL_RECORDS for a KafkaAutoCommitConsumer, -- you might fail to commit all these messages before crash, thus more duplications with the next poll.

Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zzz9h/modern-cpp-kafka.git
git@gitee.com:zzz9h/modern-cpp-kafka.git
zzz9h
modern-cpp-kafka
modern-cpp-kafka
main

搜索帮助