Git Product home page Git Product logo

node-qpubs's Introduction

qpubs

Build Status

Simple, light-weight pub-sub engine modeled on Nodejs event emitters.

  • wildcard topic prefix and suffic matching
  • support for message receipt confirmation

Summary

var QPubs = require('qpubs');
var pubs = new QPubs({ separator: '.' });
pubs.listen('my.event', function(message) {
    console.log('message == %s', message);
    // => message == 42,
    //    message == 451
})
pubs.listen('your.*', function(msg) {
    console.log('msg == %s', msg);
    // => msg == 77
})
pubs.listen('*.event', function(ev, ack) {
    console.log('ev == %s', ev);
    ack();
    // => ev == 42
    //    ev == 77
    //    ev == 451
})
pubs.emit('my.event', 42);
pubs.emit('your.event', 77);
pubs.emit('my.event', 451);

Api

new QPubs( [options] )

Construct and configure the pubsub engine.

Options:

  • separator - string that separates topic components. Default is a . dot.

listen( topic, listener(message [,cb]) )

Listen for messages published to the named topic. Each received message is passed to all interested listener()-s. The wildcard * matches leading or trailing topic components (one or the other, not both). Route components are separated by the separator string passed to the constructor. If the listener function takes a callback cb, it must be called to acknowledge receipt of the message; the emit() callback waits for all listeners to confirm.

emit( topic, message [,callback(err, errors)] )

Send the message to all the listeners listening to the topic. If a callback is given, it will be invoked once all recipients have acknowledged the message. The callback will return all errors encountered while notifying the listeners, the first error as err and the all errors in the errors array.

unlisten( topic, listener )

Make the listener stop receiving messages from the given topic. If listen() was called multiple times for this topic with this listener, each ignore() undoes one listen.

Todo

  • think about incremental checksumming, both front-to-back and back-to-front
  • time out listener callbacks
  • stateful, durable message stream subscribe/unsubscribe (with pluggable fifos)
  • ? limit on max payload? (ties up journal, etc)

Changelog

  • 0.4.2 - use newer qfifo for bugfix, remove fifo files after tests
  • 0.4.1 - add a callback to loadSubscriptions, pass deliver to closeSubscription
  • 0.4.0 - refactor qsubs into create/open/close/delete subscription
  • 0.1.2 - allow listeners to take callbacks, faster emit
  • 0.0.5 - faster unwatched subtopic skipping
  • 0.0.4 - wildcard match empty leading/trailing route components
  • 0.0.3 - hash routes by length, callback on emit()
  • 0.0.2 - working version

node-qpubs's People

Contributors

andrasq avatar

Watchers

James Cloos avatar  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.