Skip to content

Repository files navigation

The javascript message queue implementation

Javascript implementation of message queue with various delivery strategy.

Features

  1. Round-robin and broadcast message delivery strategy.
  2. Various usages:
    • Into same node.js process.
    • Inter process.
    • Inter platform (node.js and browser).

Installation

npm install node-queue-lib

Simple Usages

see example

varQueue=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');

Inter process usages

server message queue:

see example

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');

Inter platform usages

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>

Review examples

npm install node-queue-lib
cd ./node_modules/node-queue-lib/examples

run core test:

node core.js

run client-server test:

node server.js
node client.js

For run browser test locate you browser to http://localhost:8888

Run tests

For run tests you must have installed grunt.

grunt test

License

The 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.

About

Native javascript message queue implementation

Resources

Stars

20 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages