Skip to content
bradygaster edited this page May 13, 2012 · 7 revisions

This article explains how to use the Windows Azure Service Bus backplane for SignalR. Introduced by Clemens Vasters on his blog and distributed via this NuGet package, this backplane uses the Windows Azure Service Bus as a messaging layer.

Setup

### Service Bus Setup ###

You'll need to create a Service Bus Namespace to be used by SignalR. First, create a namespace using the Windows Azure management portal.

Create a Windows Azure Service Bus

### Setting up NuGet References ###

Install the SignalR libraries using NuGet:

Install-Package SignalR

Install the SignalR.WindowsAzureServiceBus package using NuGet:

Install-Package SignalR.WindowsAzureServiceBus

## Wiring Up the Windows Azure Service Bus Provider ## To wire up the service bus implementation, you'll need to add a little code to your App_Start or Global.asax.cs file, or by use of a custom IHttpModule. The use of a single extension method allows for the wire-up process, the signature of which is displayed below.
UseWindowsAzureServiceBus
(
   serviceBusNamespace, /* the service bus namespace prefix */
   serviceBusAccount,   /* "owner" or some other account */
   serviceBusAccountKey, /* the key, which can be copied from the Windows Azure portal */
   topicPathPrefix, /* the prefix applied to the name of each topic used */
   numberOfTopics /* how many topics across which messages will be sharded */
);
### Where to find the correct values ###

You'll find the correct value for the serviceBusNamespace field by selecting the correct namespace in the administration console.

The Namespace value

Scroll down in the properties window to find the correct values for the serviceBusAccount and serviceBusAccountKey values. Find the "View" button and click it to see the account and key values.

Finding the default key

When the dialog opens you'll see GUI elements that make copying the two values easy.

Copying the values to the clipboard

### Sample Global.asax.cs Usage ### The code below demonstrates how to wire up the Service Bus from within a C# Global.asax file. The values copied from the Windows Azure Service Bus administration dialogs has been pasted into the C# file.
using System;
using SignalR.WindowsAzureServiceBus;

namespace WindowsAzureServiceBusBackedSignalR
{
    public class Global : System.Web.HttpApplication
    {
        private string serviceBusNamespace = "SignalRDemoNamespace";
        private string serviceBusAccount = "owner";
        private string serviceBusAccountKey = "sFH3zkD3uaEu6hu83rt6tyXt7tUghj8kq5rmQ2+sddsdfzwVIKMaLUegc=";
        private string topicPathPrefix = "mywebapp";
        private int numberOfTopics = 1;

        protected void Application_Start(object sender, EventArgs e)
        {
            SignalR.GlobalHost.DependencyResolver.UseWindowsAzureServiceBus(
                serviceBusNamespace, /* the service bus namespace prefix */
                serviceBusAccount,   /* "owner" or some other account */
                serviceBusAccountKey, /* the key, which can be copied from the Windows Azure portal */
                topicPathPrefix, /* the prefix applied to the name of each topic used */
                numberOfTopics /* how many topics across which messages will be sharded */
                );
        }
   }
}

Note, this web site is an ASP.NET site that runs in an Azure web role. The Visual Studio 2010 project is visible below. Currently, the Service Bus backplane is only supported by sites which run as Web Roles. A later release will allow for non-Web Role sites so that typical sites can make use of Service Bus.

Site running as a Windows Azure Web Role

### What to Expect ### When the site runs and SignalR messages are transmitted, new topics will appear in the Windows Azure administration panel. Subscriptions also appear, that reflect the name of the client machine connecting to the Service Bus to use it in the SignalR transmission.

Site running as a Windows Azure Web Role

To increase the number of topics used by the Service Bus (and therefore increase throughput and performance), increase the numberOfTopics field.

private int numberOfTopics = 4;

This will result in more topics being created in the Service Bus namespace.

Site running as a Windows Azure Web Role

Clone this wiki locally