0.0.28 • Published 9 years ago

node-queue-lib v0.0.28

Weekly downloads
4
License
-
Repository
github
Last release
9 years ago

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

var Queue = require('node-queue-lib/queue.core');

var queue = new Queue('Queue name', 'broadcast');

// subscribe on 'Queue name' messages
queue.subscribe(function (err, subscriber) {
    subscriber.on('error', function(err){
        //
    });
    subscriber.on('data', function (data, accept) {
        console.log(data);
        accept(); // accept process message
    });
});

// publish message
queue.publish('test');

Inter process usages

server message queue:

see example

var SocketIoBridgeServer = require('node-queue-lib/lib/net/socket-io-bridge-server');
var QueueServer = require('node-queue-lib/lib/core/node-queue-server');
var http = require('http');

// TCP port for incoming connections
var port = 80;

// Create Socket.IO transport bridge
var serverBridge = new SocketIoBridgeServer(port, function() {
	// return http server instance
	return http.createServer();
});

// Create server and start listening
var server = new QueueServer( { serverBridge : serverBridge } );

client: see example

var Queue = require('node-queue-lib');

var url = 'http://localhost';

// create queue instance
var queue = new Queue( url, 'test-queue', 'broadcast' );

// subscribe on 'Queue name' messages
queue.subscribe(function (subscriber) {
    subscriber.on('error', function(err){
        //
    });
	subscriber.on('data', function (data, accept) {
		console.log(data);
		accept(); // accept process message
	});
});

// publish message
queue.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>

    <script src="queue.client.js"></script>

    <script>
        (function(){
            var url = 'http://localhost';

            // create queue instance
            var queue = new queuelib.Queue( url, 'test-queue', 'broadcast' );

            // subscribe on 'Queue name' messages
            queue.subscribe(function (err, subscriber) {
                subscriber.on('error', function(err){
                    //
                });
                subscriber.on('data', function (data, accept) {
                    document.write(data);
                    accept(); // accept process message
                });
            });

            // publish message
            queue.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.

0.0.28

9 years ago

0.0.27

10 years ago

0.0.26

10 years ago

0.0.25

10 years ago

0.0.24

10 years ago

0.0.23

10 years ago

0.0.22

10 years ago

0.0.21

10 years ago

0.0.20

10 years ago

0.0.19

10 years ago

0.0.18

10 years ago

0.0.17

10 years ago

0.0.16

10 years ago

0.0.15

10 years ago

0.0.14

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago