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

Kafka of message queue (consumption semantics)

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

1. An introduction to consumption semantics

   at last once: consume at least once (multiple consumption of a message may result in repeated consumption of data)

     reason: when Proudcer generated data, it was already written in broker, but due to the network exception of broker, no ACK was returned. If Producer thinks that the data has not been written successfully, producer will write again, which is equivalent to a piece of data, and has been written multiple times.

   at most once: consume at most once. For messages, it is possible to consume once or not at all.

    reason: when generating data, producer may not succeed in writing data. If broker skips this message, the data will be lost and consumer will not be able to consume.

   exactly once: yes and only once. This is what we need, that is, accurate consumption.

The scenario of consumption semantics in 2.kafka

   at last once: you can first read the data, process the data, and finally record the offset. Of course, if you crash before recording the offset, the new consumer will repeatedly consume this data, resulting in "at least one time"

   at most once: you can read the data first, then record the offset, and finally process the data. In this way, it is possible to crash the data before it is processed in time after the offset, causing the new consumer to continue to process from this offset. Then the data that has not been processed before it has time to be processed will never be processed, resulting in "maximum consumption".

   exactly once: this can be solved by dividing the submission into two phases: once the offset is saved, and once the message is processed successfully.

How to write data accurately in 3.kafka?

Idempotent operation is guaranteed when writing data on the A:Producer side:

Idempotency: only one piece of data is written to the same data no matter how many times it is operated. if it is written repeatedly, the execution is not successful.

When B:broker writes data, atomic operations are guaranteed to either succeed or fail. (retry again and again without success)

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

Internet Technology

Wechat

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

12
Report