tattletale

A pub/sub service for integrated web-apps

npm install tattletale
4 downloads in the last month

TattleTale

A Pub/Sub System for integrated Web-Apps

It's basically a Client-API that uses MQTT to communicate events between different parts of a web-application. For example an API backend could notify other pieces that a new item has been written.

At the same time, an indexer would then load that item and index it so that it can be found.

This is a simple wrapper around MQTT, that abstracts the API away a bit. The purpose is to reduce the capabilities so that you could easily replace MQTT if you find out that it does not meet your demands.

The one extra facility it provides over MQTT is that all messages are signed with a shared secret key using an SHA256-HMAC. The point of this is that you do not want to have anyone injecting messages into your application. While your message stream should be secired via TLS and the like, you should not rely solely on that. A simple HMAC is a good tradeof between simplicity and security, especially since the latter can be enhanced at lower levels.

Installation

To work this API requires an MQTT broker. The two most commonly used are:

But basically any old broker should do.

npm install tattletale

Usage

require('tattletale')({ host:'mqtt.broker.host', port:1883, app:'an-application-name', key:'a-secret-key' }, function(err, tattletale) {
  tattletale.event('namespace','eventname', function(src, evt) { … }); // listen to events
  tattletale.event('namespace','eventname'); // stop listening to events
  tattletale.event('namespace','eventname', { <value> }); // emit an event

  tattletale.state('namespace','eventname', function(src, evt) { … }); // listen to state-changes
  tattletale.state('namespace','eventname'); // stop listening to state-changes
  tattletale.state('namespace','eventname', { <value> }); // trigger a state-change

  tattletale.action('namespace','eventname', function(src, evt) { … }); // listen to state-changes
  tattletale.action('namespace','eventname'); // stop listening to state-changes
  tattletale.action('namespace','eventname', { <value> }); // trigger a state-change
});

Concepts

The idea is to provide loosely coupled web-services an easy way to communicate with each other. For this purpose tattletale knows of three distinct types:

  1. Events - something that happens
  2. States - the state of something
  3. Actions - things that you want to happen

These are communicated over MQTT and their difference is in their MQTT properties:

  • Events - QOS is 0
  • States - QOS is 0 but the message is retained
  • Actions - QOD is 3
npm loves you