albert

An HTTP event server in Node.js

albert - managing events no matter the language

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.

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.

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

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");
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);
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

Opens an HTTP stream without time, with Connection: keep-alive and Transfer-Encoding: chunked, to listen for incoming events matching EVENT_NAME_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/

Registers a HTTP POST callback URL that will be called when incoming events match EVENT_NAME_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/

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/

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/

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