2
votes

I'd like to use Azure to host my web application, for instance CloudService web role or Azure Websites, inside the application I use SignalR to connect client and server.

Since I scaled two instances for my web roles, it seems I came across a very common problem, the SignalR could not find the correct original instance. The client JavaScript said it was already started, but the server hub OnConnected event randomly not raised, so were the server methods which intended to be called by clients, all these strange issues happened randomly.

Once I changed the instance to be one, all the problems gone. So can anyone explain what happened when the client call server method, why sometimes the server seems not response properly?

I found the post, can Azure Service Bus solve this issue?

1

1 Answers

3
votes

Yes, you need to use the azure service bus. Otherwise the connections are stored in memory on the given server and the other server will know nothing about them. Once you create the service bus, just reference it in the startup class.

public void Configuration(IAppBuilder app)
{
    System.Diagnostics.Trace.TraceInformation("SignalR Startup > Configurtion start");
    // Any connection or hub wire up and configuration should go here
    string connectionString = "XXX";
    GlobalHost.DependencyResolver.UseServiceBus(connectionString, "TopicName");

    ...
}

You will also need to get a reference to the context in each of your hub methods:

  var context = GlobalHost.ConnectionManager.GetHubContext<HubName>();

It's easy peasy :)