| h1. Distributed ID Queue |
| |
| h2. *IMPORTANT* \- We recommend that you do NOT use ZooKeeper for Queues. Please see [[Tech Note 4|https://cwiki.apache.org/confluence/display/CURATOR/TN4]] for details. |
| |
| h2. Description |
| This is an alternate version of [[Distributed Queue|distributed-queue.html]] that supports assigning IDs to the items |
| added to the queue. Items put into the queue are guaranteed to be ordered (by means of ZK's PERSISTENT_SEQUENTIAL node). |
| If a single consumer takes items out of the queue, they will be ordered FIFO. If ordering is important, use a LeaderSelector to nominate a single consumer. |
| |
| h2. Participating Classes |
| * QueueBuilder |
| * QueueConsumer |
| * QueueSerializer |
| * DistributedQueue |
| |
| h2. Usage |
| h3. Creating a DistributedIdQueue |
| See [[Distributed Queue|distributed-queue.html]] for details of using the builder, the only difference is to use the {{buildIdQueue()}} method. |
| |
| h2. General Usage |
| The queue must be started via the {{start()}} method. Call {{close()}} when you are done with the queue. |
| |
| To add messages to the queue: |
| {code} |
| queue.put(aMessage, messageId); |
| {code} |
| |
| To remove messages from the queue: |
| {code} |
| int numberRemoved = queue.remove(messageId); |
| {code} |
| |
| Your consumer ({{QueueConsumer.consumeMessage()}}) will get called as messages arrive. |
| |
| The lock safety and error handling are the same as for [[Distributed Queue|distributed-queue.html]]. |