Fork me on GitHub

Simple Distributed Queue

IMPORTANT - We recommend that you do NOT use ZooKeeper for Queues. Please see Tech Note 4 for details.


A drop-in replacement for the DistributedQueue that comes with the ZK distribution.

Participating Classes

  • SimpleDistributedQueue


Creating a SimpleDistributedQueue

public SimpleDistributedQueue(CuratorFramework client,
                              String path)
client - the client
path - path to store queue nodes

Add to the queue

public boolean offer(byte[] data)
             throws Exception
Inserts data into queue.
data - the data
true if data was successfully added

Take from the queue

public byte[] take()
           throws Exception
Removes the head of the queue and returns it, blocks until it succeeds.
The former head of the queue

NOTE: see the Javadoc for additional methods

Error Handling

It is strongly recommended that you add a ConnectionStateListener and watch for SUSPENDED and LOST state changes.