How to implement zookeeper's queue management (file system, notification mechanism)?

Alibaba cloud Q & A 2022-02-13 06:12:47 阅读数:205

implement zookeeper queue management file

Zookeeper Queue management ( file system 、 A notification mechanism ), How to achieve ?

Take the answer 1:

Two types of queues :

(1) Synchronous queue , When the members of a queue gather , This queue is only available , Otherwise, wait for all members to arrive .

(2) Queue by FIFO Mode of entry and exit operation .

The first category , Create a temporary directory node under the contract directory , Whether the number of listening nodes is the number we require .

The second category , It is consistent with the basic principle of control sequence scenario in distributed lock service , It's numbered , List by number . Create... In a specific directory PERSISTENT_SEQUENTIAL node , When the creation is successful Watcher Notification waiting queue , The queue deletes the node with the smallest serial number for consumption . In this scenario Zookeeper Of znode Used for message store ,znode The stored data is the message content in the message queue ,SEQUENTIAL The sequence number is the number of the message , Take it out in order . Because the created node is persistent , So don't worry about the loss of queue messages .

copyright:author[Alibaba cloud Q & A],Please bring the original link to reprint, thank you.