albert

An HTTP event server in Node.js

npm install albert
4 downloads in the last week
6 downloads in the last month

albert - managing events no matter the language

Image

albert is an event-message server written in Node.js to be plugged into Node's HTTP server module. It allows for sending events across several applications programming languages.

albert is implemented as a middleware handler(based on Connect) and an accompanying middleware plugin.

How it works

Albert strives to make the following possible:


// Firing an event in Node.js
object.emit("event_name", data);

// Capturing the same event in C#
Albert.On += (object sender, AlbertEventArgs e) => {
    if(e.EventName == "event_name") {
        Console.WriteLine("Win win!");
    }
};

To send and capture events between different programs, in different languages, from different locations. This is made possible by using a webserver(for easy configuration and maximum compatability) as a message handler.

How to serve

First, setup the server by using one of either method:

Node.js middleware
var albert = require('albert')
, http = require('http');
var app = albert() //the middleware handler
    .use(albert.eventHandler()); // The event handler plugin, does not fire next(), so keep at bottom of stack

http.createServer(app).listen(30301, "127.0.0.1");
Node.js with Express
var albert = require('albert')
, http = require('http')
, express = require('express');
var app = express();
app.use(albert.eventHandler()); // The event handler plugin, does not fire next(), so keep at bottom of stack
app.listen(30301);
Server(install via npm install -g)
albert-server -h 127.0.0.1 -p 30301

Then, use sample code from https://github.com/ArmedGuy/albert-clients or write your own wrapper, and specify the server that was setup

Specification

Note: EVENTNAME_OR_MASK can use wildcards in the form of an asterisk()

Implemented

/listen/EVENTNAME_OR_MASK*

Opens an HTTP stream without time, with Connection: keep-alive and Transfer-Encoding: chunked, to listen for incoming events matching EVENTNAME_OR_MASK*. All output is in the form of an JSON object followed by CRLF(\r\n). The first line after opening a connection always looks like:

{"listening": true, "event": "EVENT_NAME_OR_MASK_*", "id": "listener_id"}

Stream is open until connection is lost by the client

Available aliases for /listen/:

  • /on/

/callback/EVENTNAME_OR_MASK*/base64_encode(callback_url)

Registers a HTTP POST callback URL that will be called when incoming events match EVENTNAME_OR_MASK*. The return data is an raw JSON object in the format:

{"event":"event_name", "id":"event_id", "status":"OK or ERROR or CUSTOM", "progress": "less or equal to 100", "data": "mixed data from event"}

Available aliases for /callback/:

  • None

/emit/EVENT_NAME (POST version)

Emits an event on the server, with parameters in the form of an JSON object as the POST data. The data must not be empty, if not passing arguments(such as status, ok or data), pass an empty JSON object

Format for POST data:

{"status": "OK or ERROR or CUSTOM", "progress": "less or equal to 100", "data": "mixed data from event"}
  • If status is left out, it defaults to OK.
  • If progress is left out, it defaults to 100.
  • If data is left out, it defaults to empty.

Returns an JSON object containing the id of the event, incase you want to update an event's progress(read more)

Available aliases for /emit/:

  • /fire/

/emit/EVENT_NAME?status=OK&progress=100&data=Hi (GET version)

Emits an event on the server, with parameters in the form of GET variables

  • If status is left out, it defaults to OK.
  • If progress is left out, it defaults to 100.
  • If data is left out, it defaults to empty.

Returns an JSON object containing the id of the event, incase you want to update an event's progress(read more)

Available aliases for /emit/:

  • /fire/

/update/EVENT_ID (POST version)

Updates an existing event on the server, with parameters in the form of an JSON object as the POST data. The data must not be empty, if not passing arguments(such as status, ok or data), pass an empty JSON object

  • If status is left out, it defaults to last value.
  • If progress is left out, it defaults to last value.
  • If data is left out, it defaults to last value.

Available aliases for /update/:

  • /push/

/update/EVENT_ID?status=OK&progress=100&data=Hi (GET version)

Updates an existing event on the server, with parameters in the form of GET variables

  • If status is left out, it defaults to last value.
  • If progress is left out, it defaults to last value.
  • If data is left out, it defaults to last value.

Available aliases for /update/:

  • /push/

Planned

Link the handling albert server together with another albert server, making them share events

npm loves you