qpubs

0.1.2 • Public • Published

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

ignore( 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

Changelog

  • 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

Readme

Keywords

none

Package Sidebar

Install

npm i qpubs

Weekly Downloads

1

Version

0.1.2

License

Apache-2.0

Unpacked Size

11.1 kB

Total Files

3

Last publish

Collaborators

  • andrasq