Skip to content
Piotr Kowalski edited this page Feb 13, 2016 · 4 revisions

postal.addWireTap

description: adds a wiretap to the message bus. The wiretap is a callback that is invoked when any message is published. It is often useful for logging and/or debugging purposes, but should not be used where a normal SubscriptionDefinition would be sufficient. Extending postal through add-ons, however, might be a valid use-case for a non-logging/non-diagnostics wire tap. The postal.federation base plugin for federating postal instances (between iframes/workers, for example, with postal.xframe) utilizes wire taps in order to collect messages to be sent to the remote instance(s) of postal.

returns: an anonymous function that can be used to remove the wiretap (by invoking it).

A wiretap callback can take up to two arguments:

  • data - the data (message body) of the published message
  • envelope - the full envelope of the published message, which may include up to:
    • channel - the channel name (string)
    • topic - the topic (string)
    • timeStamp - the date/time the message was published
    • data - the value of the published message (message body)

Example Usage:

var tap = postal.addWireTap( function( d, e ) {
    console.log( JSON.stringify( e ) );
});

// later, to remove the wiretap
tap();

Be sure to check out the postal.diagnostics add-on, which takes advantage of wire tap functionality.

Clone this wiki locally