Bayeux is one of the few standard protocols for publish-subscribe messaging on the web. Today we announce Bayeux compatibility in the Fanout Cloud realtime push service. When you publish JSON objects through our service, they can be received by any Bayeux-compatible client library, such as Faye.

Connecting is easy. The Bayeux service lives at a base URL of the form:

http://{realm-id}.fanoutcdn.com/bayeux

Substitute {realm-id} with your Realm ID. Alternatively, you can configure a custom domain instead. Prefix any channels with a slash (“/”) before subscribing. Here’s an example of how to listen on a Fanout Cloud channel called test using Faye:

var client = new Faye.Client('http://12345678.fanoutcdn.com/bayeux');
client.subscribe('/test', function (data) {
console.log('got data: ' + data);
});

As an extra convenience, we host the Faye client library on our web service, which you can include:

<script src="http://12345678.fanoutcdn.com/bayeux/static/faye-browser-min.js">
<script>

This feature is introduced in the same spirit as we had done with XMPP publish-subscribe compatibility awhile back. Through the use of standard protocols, “lock-in” is reduced and client implementation choice expands. For example, you can use the FayeSwift client library to connect to our service. If you are ever unsatisfied with Fanout, you can migrate to your own Bayeux server without changing client code.

There are now three ways to receive JSON messages through Fanout Cloud: Bayeux, XMPP, and FPP (our home-grown protocol). You can have a mix of clients connected to the same channel using different protocols, and any JSON messages published will be delivered to all clients.

Happy pushing!