Kafka中多個partition怎麼保證跨區消費是有序的

@Author  : Spinach | GHB
@Link    : http://blog.csdn.net/bocai8058

官方說明

這個問題嚴格來說是肯定有的,kafka只能保證分區內的有序性。

下面是kafka作者Jay Kreps的blog中介紹kafka設計思想的一段話:

Each partition is a totally ordered log, but there is no global ordering between partitions (other than perhaps some wall-clock time you might include in your messages). The assignment of the messages to a particular partition is controllable by the writer, with most users choosing to partition by some kind of key (e.g. user id). Partitioning allows log appends to occur without co-ordination between shards and allows the throughput of the system to scale linearly with the Kafka cluster size.

(每個分區都是一個完全有序的日誌,但是分區之間沒有全局排序(除了你的消息中可能包含的一些掛鐘時間)。將消息分配給特定分區是可由編寫者控制的,大多數用戶選擇通過某種密鑰(例如用戶id)進行分區。分區允許在沒有分片之間協調的情況下發生日誌追加,並允許系統的吞吐量與Kafka羣集大小線性地擴展。)

解決方法

嚴格說,kafka是無法保證全局消息有序的,沒有這個機制,只能局部有序。

但是如果只有一個分片和一個消息的生產者,那麼就相當於消息全局有序了。如果有多個消息生產者,就算只有一個分片,如果這些生產者的消息都發給這個分片,那kafka中的消息連局部有序都沒有辦法了。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章