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.
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.
Once created it should be retrieve the connection string, that will be used in the web.config file of the application.
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.
A new Cloud Project will be added to the solution, than right click on the new project and Publish.
The publish process require a storage account, which can be selected from an existing or created a new one.
In the next step, you need to select the Cloud Service created above.
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.
You can find the project here.
Leave a Reply