Skip to content

Instantly share code, notes, and snippets.

@matzew
Last active December 14, 2015 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matzew/bd4f3c41e1114c225eb1 to your computer and use it in GitHub Desktop.
Save matzew/bd4f3c41e1114c225eb1 to your computer and use it in GitHub Desktop.
AG Notifier API

Hello!

Today, I had a brief chat with Kris about a potential AeroGear Notifier Client API...

The basic idea is to wrap messaging APIs (e.g. Stomp.js, Vertx's eventbus or Socket.io/Engine.io) behind a common client 'interface'.

Basically the AeroGear-Notifier should be able to connect to a messaging system in order to subscribe to a channel to reveice messages from that channel. The AG-Notifier is also able to publish messages to ANY channel. Of course, unsubscribe and disconnect are required too...

Sure... the above is not (YET) really a SPEC, but it's start.... the JS API of the AG-Notifier (DRAFT 0.0.1) could looks like this:

/**
 * Connects to a given URL. The callback is invoked after a connection has been established. In case of an error, an Error
 * object will be passed to the callback
 */
AeroGear.Notifier.connect(String url, function callback);

/**
 * Tears down the connection. The callback is invoked after a connection has been closed. In case of an error, an
 * Error object will be passed to the callback
 */
AeroGear.Notifier.disconnect(function callback);

/**
 * Subscribes to a channel. The callback function is invoked for every message, received on the given channel.
 */
AeroGear.Notifier.subscribe(String channel, function callback);

/**
 * Removes the subscription of the given channel.
 */
AeroGear.Notifier.unsubscribe(String channel);

/**
 * Publishes a message to a given channel
 */
AeroGear.Notifier.publish(String channel, Object message);

Perhaps a STATE-MASHINE would be nice as well:

AeroGear.Notifier.CONNECTING = 0;
AeroGear.Notifier.CONNECTED = 1;
AeroGear.Notifier.DISCONNECTING = 2;
AeroGear.Notifier.DISCONNECTED = 3;

Implementation of the Adapters

The different adapter implementations will be done separately: ag-notifier-vertx.js...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment