Faye is a simple Http Pub/Sub server initially implemented by John Coglan in Ruby, and also later ported by himself to Node.js. The version for Node.js implements the Bayeux protocol, which at first glace, many of us known as http long polling.
This project just represents another alternative to Socket.IO, which also works for client applications that are not necessarily implemented within a web browser. As many http pub/sub engines out there, Faye also uses the idea of channels for routing messages, and it ships with two message repositories out of the box, a repository that runs in memory and a repository that stores the messages in REDIS.
On other hand, we have “IISNode”, one the coolest projects announced by Microsoft to host Node.js applications in IIS. One of the things you can do with IISNode is to run websites implemented with express or connect, and Faye can also be attached to an application implemented with connect, so we can this use this common denominator to mount a Faye server with IISNode.
This is also relatively attractive if you want to run your own pub/sub server in Windows Azure using IISNode as it was announced today.
The code for the Faye server looks as follow (server.js),
A few things to notice here,
- The listen port is provided by IIS through the PORT environment variable.
- The application is hosted in IIS under the virtual directory “node/faye-node”, and “myapp” is just a mapping I defined for the application using connect.
- The Faye server is configured to listen to request messages on “node/faye-node/myapp/faye”
If you take a look at the web.config file for this application, the URL routing module is used to redirect all the traffic to “myapp” to this node application (server.js)
Once you have the server up and running, you can configure several clients to send or subscribe messages to/from the Faye server. This is how a client application implemented in Node.js looks like,
As you can see, the complete URL is used on the client side to connect to the server. A client for Faye can also be implemented within a browser,
Faye will provide an URL for downloading the client library in the browser (myapp/faye.js).
Download the complete sample from here