官术网_书友最值得收藏!

Message producers

In Kafka, the producer is responsible for sending data to the partition of the topic for which it is producing data.

The producer generally does not write data to partitions, it creates write requests for messages and sends them to the leader broker. Partitioner calculates the hash value of the message, which helps the producer to choose which partition should be selected.

The hash value is generally calculated by the message key that we provide when writing the message to a Kafka topic. The message with a null key will be distributed in a round-robin fashion across partitions to ensure even distribution of messages. In Kafka, each partition has a leader and each read write request goes through the leader only. So a request to write messages to a partition of a topic will go through the leader broker. The producer waits for an acknowledgement of messages depending on the setting. Generally, it waits until the replication for a particular message is successfully acknowledged.

Remember that until and unless all replicas have been acknowledged to commit the message, it will not be available to read. This setting is the default and ensures that a message cannot be lost if a leader broker fails.

However, you can set the configuration for acknowledgement to 1, which assumes that if a message is committed by the leader, it will be available to read and the Kafka producer can produce the next messages. This setting is dangerous because, if brokers fail before other replicas commit the message, the message will be lost. This leads to less durability but high throughput.

However, it's better to compromise on throughput if your consumer system does not want to lose a single message as part of the application. We will talk in detail about the producer in the next chapter.

主站蜘蛛池模板: 界首市| 灵川县| 汉源县| 洛扎县| 绵阳市| 郯城县| 定州市| 湾仔区| 凌云县| 晋宁县| 开封县| 定远县| 溧阳市| 兴城市| 图木舒克市| 蓝田县| 大邑县| 广汉市| 什邡市| 长宁县| 阿拉善左旗| 肥西县| 靖西县| 曲阜市| 永清县| 安义县| 万源市| 大埔区| 东丽区| 剑川县| 治多县| 台东市| 嫩江县| 房产| 纳雍县| 麟游县| 大港区| 瓮安县| 郁南县| 重庆市| 兴文县|