Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to choose Partition when Kafka publishes a message

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article is about how to choose Partition when Kafka publishes a message. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

How to choose a Partition when Kafka sends a message to a Topic with multiple Partition. Perhaps most people already know that when Kafka defaults (when key is null), it uses the Round-robin strategy, that is, both rain and dew, fengshui turns, and the implementation class is DefaultPartitioner. But in our practical application, in order to keep the relevant messages in order to arrive, we must send them to the specified Partition. The method can be

Specify Partition number

Specify Key

Custom Partitioner-implements org.apache.kafka.clients.producer.Partitioner and registers through properties

You should also consider which Partition will be chosen when the subsequent message key is null when a Key or Partition number is specified to send the message. Finally, consider whether the list of messages Consumer gets each time it poll contains only one Partition source or can have multiple Partiton sources.

In order to complete this experiment, we can build a local Kafka environment and simply build an Apache Kafka distributed message system. After Zookeeper and Kafka start normally, we create a Topic partition-test with a number of 3 Partition with the following command

Bin/kafka-topics.sh-create-zookeeper localhost:2181-replication-factor 1-partitions 3-topic partition-test

Thank you for reading! This is the end of the article on "how to choose Partition when Kafka publishes news". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report