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

后端 未结 5 860
忘掉有多难
忘掉有多难 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:28

    Here is your starting point:
    partitioner.class setting in your Properties instance. In Kafka, the default implementation is kafka.producer.DefaultPartitioner.

    The goal of that setting is:

    The partitioner class for partitioning messages amongst sub-topics. The default partitioner is based on the hash of the key.

    This means that if you want to change the behaviour of the default partitioner , then you need to create your own implementation of kafka.producer.Partitioner interface.

    I would suggest to be really careful when creating your own strategy and really, test it a lot and monitor your topics and their partitions.

提交回复
热议问题