Azure Service Bus ScaleOut

ScaleOut using Azure Service Bus is a very popular alternative! It is smooth and super easy to setup. You do not have to write a single line of code!

In this sample we will extend the sample we had in the default ScaleOut. If you do not remember we had a solution with 2 Console Applications. We will re-use that and scale over Azure instead of using the P2P socket.

When using the Azure Service Bus ScaleOut it is common to also host XSockets on Azure in a WorkerRole. That is covered in the Hosting section. A great benefit of hosting XSockets in a worker role when using the ScaleOut is that the WorkerRole will auto-scale and use Azure Service Bus as ScaleOut and you do not have to do anything!

Pre-Req

Azure Account

Azure SDK

Service Bus Account

Create a new Service Bus Namespace if needed at https://manage.windowsazure.com. Then you select your existing (or new) service bus. When selected you can click connection information at the bottom. This will show you the connection string and let you copy it.

Nuget packages

Since you (obviously) will be using Azure you will need to install an extra package.

Install-Package WindowsAzure.ServiceBus

ScaleOut Module for Azure Service Bus

Adding/Configuring the ScaleOut module for Azure Service Bus is really easy. It comes down to 2 simple steps.

Add the Item-Template

Add a unique server Id and the connection-string to your Azure Service Bus

1. Add the Item-Template

Under Add -> New Item you will find XSockets.NET 5 and the Azure Service BusScaleOut template.

This template will provide you with a module that overrides the default ScaleOut.

2. Add the ConnectionString & Server Id

This new ScaleOut module will need 2 AppSettings. One for the Azure Service Bus and another to identify each server with a unique id. I use GUID's for ServerId, but as you can see below any unique string is ok.

These 2 steps have to be repeated for both projects since they both will need to scale to our Azure Service Bus. Remember to set a unique server Id in the App.config. You cant have 2 identical Id's for the servers. The scaling will fail if the id is not unique!

Test the Azure Service Bus Scaleout

Just as we did in the Default ScaleOut we use Putty to test the scaling over Azure Service Bus.

We open two instances of Putty and connect one to localhost:8080 and the other to localhost:8181

I configured the solution to run both Console Applications on start, so this is what we got after starting the debugger.

Then we start 2 instances of Putty and connects them to each server

After sending in the handshake PuttyProtocol, we open a controller instance by sending generic|1|
If you have no idea what this means read the The Basics section as well as the Controllers section

Now the client to the right sends in a message on the generic controllergeneric|foo|bar. The message then arrives at both clients since the server ScaledOut the message coming in to the Azure Service Bus. Then the Service Bus sends the message to the other servers connected to the same Service Bus

The Code

If you are curious abut the code without actually testing this... The item-template that we added looks like this.

Note: If you host an Azure Worker Role and scale the Worker Role you will have to make sure that you get unique id's for each server. Feel free to contact us if you need some guidance!