Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

info@ssw.com.

au
SSW www.ssw.com.au
Australia Phone (+ 61) 2 9953 3000

SignalR – Scale Out Azure Website via Service Bus


Prerequisites
- SignalR
- Azure Service Bus

IQueue
- Peek
- GetMessage
- DeleteMessage

Overview

Figure: We need to be able to scale our SignarlR implementation to support multiple web
servers. This is achieved via a Backplane. When hosting on Windows Azure, we use the
Service Bus Backplane (not SQL Server or Redis).
In Summary
- In SignalR, every message is sent through a message bus.
- The backplanes work by replacing the default IMessageBus with a bus designed for
that backplane.
- Each server instance connects to the backplane through the bus.
- When a message is sent, it goes to the backplane, and the backplane sends it to
every server.
- When a server gets a message from the backplane, it puts the message in its local
cache. The server then delivers messages to clients from its local cache.
- For each client connection, the client’s progress in reading the message stream is
tracked using a cursor. (A cursor represents a position in the message stream.)
- If a client disconnects and then reconnects, it asks the bus for any messages that
arrived after the client’s cursor value.
- The cursor mechanism works even if a client is routed to a different server on
reconnect.
- The backplane is aware of all the servers, and it doesn’t matter which server a client
connects to.
© SSW 563630605.docx Version: 15
Building software people understand. Our core competency is helping you to deliver awesome Page 1 of 5
Microsoft solutions. We build the very best solutions with SharePoint, CRM and .NET
Details on Consulting Services
Step: Create a Service Bus Namespace
Log into the Azure Portal
Go to the Service Bus area
Create a new Service Bus Namespace

Figure: When the namespace is created, select it and click Connection Information

Figure: Hover over the end of the connection string line, and then click the Copy icon.
The connection string is now pasted into your clipboard.
Save it for use somewhere else.

Step: Create an MVC Application


Create a new Team Project on VisualStudio.com. Use TFS-Git
Clone it locally.
Add a new MVC Application: No Authentication
Create a Windows Azure Webset
Configure Continuous Deployment from VisualStudio.com to your Azure Website
Push your code to VisualStudio.com
Check your website to ensure the MVC application has deployed.

© Superior Software for Windows Pty Limited 563630605.docx Version: 15


info@ssw.com.au | www.ssw.com.au Phone +61 2 9953 3000 | Fax +61 2 9953 3105 Page 2 of 5
Update the Website with the SignalR Chat Demo

To create the chat application, follow the steps in the tutorial Getting Started with SignalR
and MVC 5.

Step: Implement the Azure Service Bus Backplane

Add the following nugget packages

Install-Package Microsoft.AspNet.SignalR
Install-Package Microsoft.AspNet.SignalR.ServiceBus

public void Configuration(IAppBuilder app)


{
string connectionString = "Service Bus connection string";
GlobalHost.DependencyResolver.UseServiceBus(connectionString, "Chat");

app.MapSignalR();
// ...
}
Figure: Configure the backplane by adding the above to startup.cs

This code configures the backplane with the default values for TopicCount and
MaxQueueLength. For information on changing these values, see SignalR Performance:
Scaleout Metrics.

Push to VisualStudio.com to kick off a deployment.

© Superior Software for Windows Pty Limited 563630605.docx Version: 15


info@ssw.com.au | www.ssw.com.au Phone +61 2 9953 3000 | Fax +61 2 9953 3105 Page 3 of 5
Step: Go to the Azure Dashboard and check the activity

Figure: To see the subscriptions and message activity, open the Azure portal, select the
Service Bus namespace, and click on “Topics”.

Step: Enable WebSockets on Azure Web Site


WebSockets needs to be explicitly enabled in Azure Web Sites to be used in a SignalR
application; otherwise, other protocols will be used.

WebSockets is only available on Basic and Standard tier Azure Web Sites, and that the
number of active Web Socket connections is restricted for Basic tier sites.
See Web Sites Pricing Details for more information. http://azure.microsoft.com/en-us/pricing/details/web-sites/

1. Open your web site in the Azure Management Portal, and select Configure.
2. In General Settings | .NET framework version, choose ‘4.5’
3. In the WebSockets setting, select On.
4. Select Save to save your changes.

Resources:
Read the following

Using Signalr with Azure Web Sites


(For info on enabling web sockets)
http://www.asp.net/signalr/overview/signalr-20/getting-started-with-signalr-20/using-signalr-
with-azure-web-sites

Introduction to Scaleout in SignalR


http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-in-signalr

SignalR Scaleout with Azure Service Bus

© Superior Software for Windows Pty Limited 563630605.docx Version: 15


info@ssw.com.au | www.ssw.com.au Phone +61 2 9953 3000 | Fax +61 2 9953 3105 Page 4 of 5
http://www.asp.net/signalr/overview/signalr-20/performance-and-scaling/scaleout-with-
windows-azure-service-bus

Azure Service Bus Overview


http://azure.microsoft.com/en-us/documentation/articles/fundamentals-service-bus-hybrid-
solutions/

How to Use Service Bus Topics


http://azure.microsoft.com/en-us/documentation/articles/service-bus-dotnet-how-to-use-
topics-subscriptions/

Comparing Service Bus Queues and Storage Queues


http://msdn.microsoft.com/en-us/library/azure/hh767287.aspx
http://msdn.microsoft.com/en-us/magazine/jj159884.aspx
key points: the difference in the difficulty of implementation is small.

© Superior Software for Windows Pty Limited 563630605.docx Version: 15


info@ssw.com.au | www.ssw.com.au Phone +61 2 9953 3000 | Fax +61 2 9953 3105 Page 5 of 5

You might also like