1
votes

I must be missing something when setting up SignalR to use an Azure Service Bus. I have my App Service (API - Web API 2) setup to run 3 constant instances (currently), upon startup, the API uses the Service Bus connection string and sets the appropriate topic prefix.

On the front-end, SignalR is able to connect to my API, but messages are only sometimes received by the client. My assumption is that the client only receives messages from the server to which it originally connected. This leads me to believe that SignalR is not using the Service Bus correctly. When viewing the Service Bus via Azure, I do see that topics are being created, but there are no messages in any of them (I also see subscriptions).

So, as far as I can tell, SignalR between the client and server is still using a direct connection instead of going through the Service Bus. Note that the client is using the URL of the API for the SignalR connection -- is this correct?

SignalRConfig (During app startup.)

var serviceBusConnectionString = configHelper.SignalR.ServiceBusConnectionString;
var serviceBusTopicPrefix = configHelper.SignalR.TopicPrefix;

Logger.Info("SignalR: configuring");

// Use the service bus, if specified.
if (serviceBusConnectionString != null && serviceBusTopicPrefix != null) {
    Logger.Info("SignalR: using service bus");

    GlobalHost.DependencyResolver.UseServiceBus(serviceBusConnectionString, serviceBusTopicPrefix);
}

app.MapSignalR();

The above code runs for each instance, I have no idea if this is correct or not. Perhaps that is why I am seeing multiple topics, e.g. signalr_topic_my-app-staging_0 -- 0 through 5.

Note that I've tried to follow this (outdated) tutorial: https://docs.microsoft.com/en-us/aspnet/signalr/overview/performance/scaleout-with-windows-azure-service-bus

1
Which nuget package are you using ? the nuget package from the tutorial is deprecated. You should use Microsoft.AspNet.SignalR.ServiceBusThomas
The latest Microsoft.*.SignalR*, can give specifics if needed, one I'm back in front of my pc.Josh M.

1 Answers

1
votes

Your code seems correct and it should run for each instance.

There should be 6 topics in Service Bus: signalr_topic_{TOPIC_PREFIX}_0 through to signalr_topic_{TOPIC_PREFIX}_5.

Is each instance using the same topic prefix name? If they are using different topic names then this would explain the behavior you are seeing.