How to produce messages to selected partition using kafka-console-producer?

后端 未结 5 907
忘掉有多难
忘掉有多难 2021-02-01 06:40

According to the Kafka documentation:

The producer is responsible for choosing which message to assign to which partition within the topic.

5条回答
  •  渐次进展
    2021-02-01 07:18

    According to the current state of things (Kafka>=0.10.0.1), the kafka-console-producer.sh script and the underlying ConsoleProducer java class support sending data with a key, but such support is disabled by default and has to be enabled from the CLI.

    Namely, you need to set the property parse.key. Also, if you want to use something different than a tab character, use key.separator as specified in Cedric's answer.

    In the end, the command line would be:

    kafka-console.producer.sh --broker-list kafka:9092,kafka2:9092 \
        --topic $TOPIC --property parse.key=true --property key.separator=|
    

提交回复
热议问题