Skip to content

Instantly share code, notes, and snippets.

@ben-bradley
Created July 24, 2014 16:27
Show Gist options
  • Save ben-bradley/7a3c0ffeccad974a7952 to your computer and use it in GitHub Desktop.
Save ben-bradley/7a3c0ffeccad974a7952 to your computer and use it in GitHub Desktop.
simple example of faye & express
var faye = require('faye'),
express = require('express');
var app = express(),
pubsub = new faye.NodeAdapter({
mount: '/pubsub',
timeout: 45
});
app.get('/', function (req, res) {
res.send('ok');
});
var server = app.listen(3001);
pubsub.attach(server);
// server configured, now build a client
var client = pubsub.getClient();
client.subscribe('/blargh', function (msg) {
console.log('CLIENT RX:', msg);
});
setInterval(function () {
var msg = {
ts: new Date().getTime()
};
console.log('CLIENT TX:', msg);
client.publish('/blargh', msg);
}, 1500);
// Now build a client using the non-built-in method
var otherclient = new faye.Client('http://localhost:3001/pubsub');
setInterval(function () {
var msg = {
blargh: 'honk'
};
console.log('OCLIENT TX:', msg);
otherclient.publish('/blargh', msg);
}, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment