Trying the Azure SignalR service

Totally unexpectedly I ran into something "new" in Azure: the Azure SignalR service. It's been out there for a while, but somehow I haven't come across it (to be fair, it is now one of the better-marketed services of Azure). According to the documentation, it gives you a lot of cool capabilities:

  • It basically acts as a "backend" for a SignalR service. You can create serverless SignalR applications by combining the Azure SignalR service with Azure functions (this is actually quite intriguing, I might check this out later).
  • It also gives you a built-in backpane. A backpane for a SignalR service is something that allows the dynamic scaling of SignalR applications.
  • It supports a token-based authentication model, again built-in.

I decided that this was something that I would try out myself, just for fun. So I did a little demo. To try the service, here's what you need to do:

First, create an Azure SignalR service. Most of the options are pretty self-explanatory:

When the resource is created, go ahead and copy the connection string from the Keys blade (either one is fine).

Then I simply cloned the SignalR sample from the ASP.NET Github repo and upgraded the project to .NET Core 2.2.

Next, you have to add a new NuGet package to the project: Microsoft.Azure.SignalR.

And finally, change your code a bit. In the ConfigureServices() method, add a call to AddAzureSignalR() after the AddSignalR() call and pass in the connection string you copied from the portal as the parameter:

public void ConfigureServices(IServiceCollection services)
{
  services.AddSignalR().AddAzureSignalR(connectionString);
}

And change the app.UseSignalR() to app.UseAzureSignalR() in the Configure() method:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
  if (env.IsDevelopment())
  {
    app.UseDeveloperExceptionPage();
  }
  app.UseFileServer();
  app.UseAzureSignalR(routes =>
  {
    routes.MapHub<ChatHub>("/chat");
  });
}

And that's it. Now you can run the application, and on the surface, it seems like nothing happened. But if you log in to the Azure portal and check the Metrics blade for the Azure SignalR service, you can see the number of connections or messages or whatever you configure:

That's nice. It would be even better to see the actual messages, but it's a start. Also, the fact I don't have to configure a Redis backpane myself is a strong enough benefit that I'm sold. So go ahead and check out the service yourself; you can download the modified sample from my Github repo. And be sure to check back for the Azure Function integrated version.