Scaling out a SignalR application

There are several ways to scale a SignalR web application, such as Redis, SQL Server and Azure Service Bus.
To configure an Azure Service Bus on an existing application, two configurations are required in the Azure Management Portal, an Azure Cloud Service (if not exist) and an Azure Service Bus.

Cloud Service

The Cloud Service configuration require a DNS name, the reference to the subscription, the resource group and the location.

cloud-service_small

Later this service will be used to deploy the existing application.

Azure Service Bus

There are different types of Azure Service Bus and the Topic is the tipology that support a publish/subscribe messaging communication model.

service-bus_small

Once created it should be retrieve the connection string, that will be used in the web.config file of the application.

service-bus2_small

Web.config file

In the web.config file you need to bring back the topic connection string.

<connectionStrings>
<add name="ServiceBus" connectionString="Endpoint=sb://angular-signalr.servicebus.windows.net/;SharedAccessKeyName=...;SharedAccessKey=..."/>
</connectionStrings>

Application update

In this example the application is a AngularJS application that uses SignalR.
In order to enable the application to comunicate with Service Bus, the installation of the NuGet package Microsoft.AspNet.SignalR.ServiceBus is required.
Once installed, in the Startup.cs file we need to pass the ServiceBus connection string to the SignalR GlobalHost static class.

public class Startup
{
public void Configuration(IAppBuilder app)
{
string connectionString = ConfigurationManager.ConnectionStrings["ServiceBus"].ConnectionString;
GlobalHost.DependencyResolver.UseServiceBus(connectionString, "NotificationsHub");
app.MapSignalR();
}
}

Publishing

Right click on the web application project and convert it to an Azure Cloud Service Project.

azure-conversion_small

A new Cloud Project will be added to the solution, than right click on the new project and Publish.

azure-publish_small

The publish process require a storage account, which can be selected from an existing or created a new one.

azure-publish2

In the next step, you need to select the Cloud Service created above.

azure-publish3

Once the publication process is terminated, the application is available from the cloud service address and the role instances communicate through the Service Bus.
A message dashboard is available by accessing the topic Service Bus created above.

service-bus-result_small

You can find the project here.

Advertisements
Scaling out a SignalR application

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s