如何使用kafka-console-producer将消息生成到所选分区? [英] How to produce messages to selected partition using kafka-console-producer?
问题描述
根据Kafka文档:
生产者负责选择要分配给主题中哪个分区的消息.
如何使用 kafka-console-producer.sh
将消息发送到选定的分区?
我想在邮件发送时指定某种分区ID".
更新:这个答案在2014年是正确的,但是更多当前版本的Kafka 可以通过控制台生产者生成键/值对.请参见下面的 答案
kafka-console-producer.sh不支持开箱即用地向特定分区生成消息.
但是,更新脚本以为分区ID传递一个额外的参数,然后按照@Chiron在kafka.tools.ConsoleProducer类的修改版中的帖子中所述,在自定义分区中对其进行处理应该非常简单./p>
在以下位置查看源代码
:https://apache.googlesource.com/kafka/+/refs/heads/trunk/bin/kafka-console-producer.sh https://apache.googlesource.com/kafka/+/refs/heads/trunk/core/src/main/scala/kafka/tools/ConsoleProducer.scala
According to the Kafka documentation:
The producer is responsible for choosing which message to assign to which partition within the topic.
How can I send messages to a selected partition using kafka-console-producer.sh
?
I would like to specify some sort of 'partition id' at message sending.
Update: This answer was correct on 2014, but more current versions of Kafka can produce key/value pairs via the console producer. See the below answers
kafka-console-producer.sh doesn't support producing messages to a particular partition out of the box.
However it should be pretty straightforward to update the script to pass an extra parameter for partition Id and then handle it in a custom partitioner as described in the post by @Chiron in a modified version of kafka.tools.ConsoleProducer class.
Take a look at the source code at:
https://apache.googlesource.com/kafka/+/refs/heads/trunk/bin/kafka-console-producer.sh https://apache.googlesource.com/kafka/+/refs/heads/trunk/core/src/main/scala/kafka/tools/ConsoleProducer.scala
这篇关于如何使用kafka-console-producer将消息生成到所选分区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!