Giter VIP home page Giter VIP logo

ascoltatori's Introduction

Ascoltatori

Build Status

Ascoltatori is the publish/subscribe library that supports every broker/protocol out there. This list currently includes:

  • RabbitMQ and all implementations of the AMQP protocol.
  • Redis, the fabulous key/value store by @antirez.
  • Mosquitto and all implementations of the MQTT protocol.
  • MongoDB, the documental NoSQL that is revolutioning how web apps are built.
  • ZeroMQ without a central broker, so Ascoltatori can also be used in a P2P fashion.

The source code of Ascoltatori had been annotated with dox and the generated documentation is available at: http://mcollina.github.com/ascoltatori/docs/ascoltatori.js.html

Ascoltatori is an italian word which means listeners. An Ascoltatore is therefore a single listener.

Install

npm install ascoltatori --save

Usage

Ascoltatori is built to be extremely easy to use, and can provide a useful abstraction for every compatible pub/sub broker. In this way you can choose whatever broker suits you.

var ascoltatori = require('ascoltatori');

ascoltatori.build(function (ascoltatore) {

  ascoltatore.subscribe("hello/*", function() {
    // this will print { '0': "hello/42", '1': "a message" }
    console.log(arguments); 
    process.exit(0);
  });

  ascoltatore.publish("hello/42", "a message", function() {
    console.log("message published");
  });
});

See the tests for more examples regarding RedisAscoltatore, AMQPAscoltatore, ZeromqAscoltatore, MQTTAscoltatore.

In the test/common.js file you can find all the options for all the ascoltatori.

All ascoltatori supports the use of a wildcards, so everything should work smoothly on every broker. You might find some differences, and in that case file a bug report, so I can fix them.

Ascoltatori also support the '+' operator, which match only one step in in a tree of topics:

var ascoltatori = require('ascoltatori');

ascoltatori.build(function (ascoltatore) {

  ascolatore.subscribe("hello/+", function() {
    // this will print { '0': "hello/world/42", '1': "a message" }
    console.log(arguments); 
  });

  ascoltatore.publish("hello/42", "a message", function() {
    console.log("message published");
  });
});

This is an example with both a '*' and a '+':

var ascoltatori = require('ascoltatori');

ascoltatori.build(function (ascoltatore) {

  ascoltatore.subscribe("hello/*", function() {
    // this will print { '0': "hello/world/42", '1': "a message" }
    console.log(arguments); 
  });

  ascolatore.subscribe("hello/+", function() {
    // this will not be called
  });

  ascoltatore.publish("hello/world/42", "a message", function() {
    console.log("message published");
  });
});

Configuration and dependencies

This library does not depend directly on redis, AMQP (RabbitMQ), 0MQ, MQTT.js, but rather it encourages you to pass them to the ascoltatori via an options object, like so (for Redis):

var ascoltatori = require('ascoltatori');

var settings = {
  type: 'redis',
  redis: require('redis'),
  db: 12,
  port: 424242,
  host: 192.168.42.42
};

ascoltatori.build(settings, function (ascoltatore) {

  ascoltatore.subscribe("hello/*", function() {
    // this will print { '0': "hello/42", '1': "a message" }
    console.log(arguments); 
    process.exit(0);
  });

  ascoltatore.publish("hello/42", "a message", function() {
    console.log("message published");
  });
});

By default, every ascoltatore built by the ascoltatori.build wraps every published message in a JSON format. This behaviour can be triggered off by passing a { json: false } settings object, like so:

require('ascoltatori').build({ json: false }, function(a) {
  // ...
});

If you feel one more option is missing, feel free to fork this library, add it, and then send a pull request.

Domain support

Ascoltatori properly supports the node.js domain API. To use it, you have to call the registerDomain function on your Ascoltatore, and it will take care of routing the exceptions to the given domain. Look at this example:

var ascoltatori = require('ascoltatori');
var domain      = require("domain");

var d = domain.create();
d.on("error", function() {
  console.log(arguments); 
  process.exit(0);
});

ascoltatori.build(function (ascoltatore) {

  ascoltatore.registerDomain(d);

  ascoltatore.subscribe("hello/*", function() {
    throw new Error();
  });

  ascoltatore.publish("hello/42", "a message", function() {
    console.log("message published");
  });
});

Debugging

Ascoltatori supports the clever debug package, so it is able to trigger the logging based on an external enviroment variable, like so:

$: DEBUG=ascoltatori:mqtt node exaples/mqtt_topic_bridge.js

The following debug flags are supported, one for each ascoltatore:

  • ascoltatori:amqp
  • ascoltatori:memory
  • ascoltatori:trie
  • ascoltatori:mqtt
  • ascoltatori:prefix
  • ascoltatori:redis
  • ascoltatori:zmq

Reliability

Due to the various transports Ascoltatori uses, it is impossible to garantee one of the various reliability properties across all of the transports. However, the MQTT and AMQP ascoltatori provides at-least-once semantics, which means that the message might be received more than once, but at least once.

Contributing to Ascoltatori

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
  • Fork the project
  • Start a feature/bugfix branch
  • Commit and push until you are happy with your contribution
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Makefile and package.json. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.

Contributors

Ascoltatori is only possible due to the excellent work of the following contributors:

Matteo CollinaGitHub/mcollinaTwitter/@matteocollina
Filippo de PrettoGitHub/filnikTwitter/@filnik90
David HallsGitHub/davedoesdevTwitter/@davedoesdev

LICENSE - "MIT License"

Copyright (c) 2012-2013 Matteo Collina and Contributors, http://matteocollina.com

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.

ascoltatori's People

Contributors

mcollina avatar filnik avatar davedoesdev avatar heliosmaster avatar unlucio avatar

Watchers

bjkim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.