Javascript implementation of message queue with various delivery strategy.
- Round-robin and broadcast message delivery strategy.
- Various usages:
- Into same node.js process.
- Inter process.
- Inter platform (node.js and browser).
npm install node-queue-libvarQueue=require('node-queue-lib/queue.core');varqueue=newQueue('Queue name','broadcast');// subscribe on 'Queue name' messagesqueue.subscribe(function(err,subscriber){subscriber.on('error',function(err){//});subscriber.on('data',function(data,accept){console.log(data);accept();// accept process message});});// publish messagequeue.publish('test');server message queue:
varSocketIoBridgeServer=require('node-queue-lib/lib/net/socket-io-bridge-server');varQueueServer=require('node-queue-lib/lib/core/node-queue-server');varhttp=require('http');// TCP port for incoming connectionsvarport=80;// Create Socket.IO transport bridgevarserverBridge=newSocketIoBridgeServer(port,function(){// return http server instancereturnhttp.createServer();});// Create server and start listeningvarserver=newQueueServer({serverBridge : serverBridge});client: see example
varQueue=require('node-queue-lib');varurl='http://localhost';// create queue instancevarqueue=newQueue(url,'test-queue','broadcast');// subscribe on 'Queue name' messagesqueue.subscribe(function(subscriber){subscriber.on('error',function(err){//});subscriber.on('data',function(data,accept){console.log(data);accept();// accept process message});});// publish messagequeue.publish('test');The server code is the same as above.
client: see example
<!DOCTYPE html><html><head><title>message queue example</title><scriptsrc="queue.client.js"></script><script>(function(){varurl='http://localhost';// create queue instancevarqueue=newqueuelib.Queue(url,'test-queue','broadcast');// subscribe on 'Queue name' messagesqueue.subscribe(function(err,subscriber){subscriber.on('error',function(err){//});subscriber.on('data',function(data,accept){document.write(data);accept();// accept process message});});// publish messagequeue.publish('test');})();</script></head><body></body></html>npm install node-queue-lib
cd ./node_modules/node-queue-lib/examplesrun core test:
node core.jsrun client-server test:
node server.jsnode client.jsFor run browser test locate you browser to http://localhost:8888
For run tests you must have installed grunt.
grunt testThe MIT License
Copyright (c) 2014 Gromozdov Andrey Alexandrovich.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.