https://github.com/jhurliman/node-zookeeper-queue
FIFO queue using ZooKeeper, implemented with node.js streams
https://github.com/jhurliman/node-zookeeper-queue
Last synced: 2 months ago
JSON representation
FIFO queue using ZooKeeper, implemented with node.js streams
- Host: GitHub
- URL: https://github.com/jhurliman/node-zookeeper-queue
- Owner: jhurliman
- License: mit
- Created: 2014-01-10T23:55:01.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-01-11T07:11:41.000Z (over 12 years ago)
- Last Synced: 2025-03-23T16:14:09.120Z (about 1 year ago)
- Language: JavaScript
- Size: 160 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
node-zookeeper-queue
====================
[](https://travis-ci.org/jhurliman/node-zookeeper-queue)
FIFO queue using ZooKeeper, implemented with node.js streams
## Download
The source is available for download from
[GitHub](http://github.com/jhurliman/node-zookeeper-queue).
Alternatively, you can install using Node Package Manager (npm):
npm install zookeeper-queue
## Quick Example
This library exports two different stream constructors, depending on whether
you want publish or subscribe (write or read). Both streams follow the standard
stream interface for Writable or Readable with the addition of a `destroy()`
method on SubQueue to disconnect from ZooKeeper, which is done with the `end()`
method on PubQueue.
```js
var zkQueue = require('zookeeper-queue');
var ZKPubQueue = zkQueue.PubQueue; // Inherits from streams.Writable
var ZKSubQueue = zkQueue.SubQueue; // Inherits from streams.Readable
var options = { path: '/myqueue', host: 'localhost', port: 2181 };
var subQueue = ZKSubQueue(options)
.on('connect', function() {
console.log('[SUB] Connected');
})
.on('data', function(data) {
console.log('[SUB] Received a message: ' + data.toString());
pubQueue.end();
subQueue.destroy();
})
.on('close', function() {
console.log('[SUB] Closed the queue connection');
});
var pubQueue = new ZKPubQueue(options)
.on('error', function(err) {
console.error('[PUB] An error occurred: ' + err);
})
.on('connect', function() {
console.log('[PUB] Connected. Writing "hello world" to the queue');
pubQueue.write('hello world');
})
.on('close', function() {
console.log('[PUB] Closed the queue connection');
});
```