Socket.IO is a handy tool that makes it easy to build real-time communication into your application. If you haven’t used Socket.IO before, I recommend reading the tutorial over on WindowsAzure.com. This post shows how you can scale out Socket.IO to multiple servers in order to handle many simultaneous connections by using Windows Azure Service Bus as a backing store.

The get started, you will need to create a service bus namespace and subscription. You can do this in the portal by clicking the “New” button and following the steps shown below.

createtopic

After your topic is created, install the socket.io-servicebus module by running npm as shown below.

npm install https://github.com/ntotten/socket.io-servicebus/archive/master.tar.gz

Note: I am installing my fork of the socket.io-servicebus module. The module is also available on npm, but there are updates to this fork for automatically managing subscriptions. These updates will be in the main version shortly. You can see the pull request for my updates here.

With the module installed, open up your application. For this demo, I am using an express web app, but you can use whatever frameworks you would like. Configure the service bus store for Socket.IO as shown below.

// Setup the Service Bus store for Socket.IO
var sbstore = require('socket.io-servicebus');
io.configure(function () {
  io.set("transports", ["xhr-polling"]);
  io.set("polling duration", 30);
  io.set('store', new sbstore({
    topic: nconf.get("SERVICE_BUS_TOPIC"),
    connectionString: nconf.get("CUSTOMCONNSTR_SERVICEBUS"),
    logger: io.get('logger')
  }));
});

After you have configured the service bus store you are now ready to scale your application to use as many servers as required. You can download the full source of my sample application on Github.