Invoking SignalR from Azure Function

Viewed 1377

I'm trying to set up SignalR with my Azure system. The setup is fairly standard

  • Main web portal in Azure App Service written in ASP.NET MVC
  • A cloud service worker role that performs business logic. The worker role listens on a queue that the portal writes to. I had to use a cloud service for this due to a reliance on legacy C++ business logic

When a user starts a time consuming operation from the portal, I want the cloud service to be able to inform all the connected browsers via SignalR that the cloud service is complete.

I thought I could do this using an Azure Function like a SignalR client, that could be triggered to force SignalR to broadcast a message using code in an Azure function like this

    HubConnection hub = new HubConnection(*URL OF PORTAL GOES HERE*);

    var proxy = hub.CreateHubProxy(*NAME OF HUB GOES HERE*);
    await hub.Start();
    await proxy.Invoke("Hello"); // Name of default hub method

ASP.NET MVC side, I'm also using Azure Service Bus queues, which seems to be the advice when it comes to scaling. So, in my Startup.cs I've got

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            GlobalHost.DependencyResolver.UseServiceBus(@"*SERVICE BUS CONNNECTION STRING GOES HERE*", "blah");
            app.MapSignalR();
        }
    }

Note: In order to get this to work with the latest SignalR I had to use the Microsoft.AspNet.SignalR.ServiceBus3 nuget package otherwise I just got an exception when the UseServiceBus call was made.

Now, it all appears to work. I can call the Azure function from PostMan and sure enough in my browser the signalr call comes through.

However, I'm not sure if this is the right thing to do. Will scaling work in this case or is there a better way of forcing signalr to broadcast messages out?

thanks

1 Answers
Related