Skip to content

Practical ASP.NET Core SignalR: Azure SignalR Service

Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.

Learn more about Software Architecture & Design.
Join thousands of developers getting weekly updates to increase your understanding of software architecture and design concepts.


ASP.NET Core SignalR Scaling

In this section, I’m going to cover how to deal with scaling SignalR by using the Azure SignalR Service. This is a managed service that is an alternative to using the Redis backplane that I’ve described in the previous section.

You may want to use this option as it eliminates having to manage your own Redis instance as well as dealing with a load balancers configuration of sticky sessions (client affinity). Everything is all pre-configured for you, and is a fully managed service.

This blog post is apart of a course that is a complete step-by-setup guide on how to build real-time web applications using ASP.NET Core SignalR. By the end of this course, you’ll be able to build real-world, scalable, production applications using the tools and techniques provided in this course.

If you haven’t already, check out the prior sections of this course.

  1. Course Overview
  2. ASP.NET Core SignalR Overview
  3. Basics
  4. Server Hubs
  5. HubContext
  6. Authorization
  7. Scaling with Redis

SignalR Scaling

I’ve covered the basics of scaling in the previous section and how having a web farm poses problems when using SignalR.

If you haven’t already or are need an overview of a webfarm scenario with SignalR, check out that section which covers how to scale using Redis as a backplane.

Azure SignalR Service

First thing to do is add a new resource in Azure by and search for the SignalR Service.

As you are creating the new service, when selecting the pricing tier, note that the free tier does not support changing the unit count. Meaning you are limited to 20 connections and 20k messages/day. The standard tier gives you 1k connections per unit and 1M messages/day/unit and allows you to scale up to 100 units (depending on the region).

Once created, go to the Settings > Keys page where you will need to copy the Connection String

Configuration

First, you’ll need to reference the Microsoft.Azure.SignalR package in your csproj.

From here you simply need to change the ConfigureServices() to use AddAzureSignalR() and modify the Configure() to call UseAzureSignalR()

User Secrets

Now we need to place our Azure SignalR Service connection string in user secrets. To add to our secrets via the dotnet CLI:

dotnet user-secrets set Azure:SignalR:ConnectionString "Connection String Goes Here"   

If you’re unfamiliar with user secrets, check out my blog post on handling sensitive configuration data.

That’s it. You’ll now be using the Azure SignalR Service and be able to scale to 1000’s of connections.

Get The Course!

You’ve got several options:

  1. Check out my Practical ASP.NET Core SignalR playlist on my CodeOpinion YouTube channel.
  2. Access the full course now by enrolling for free on Teachable.
  3. Follow along with the blog post series here on CodeOpinion.com
    1. Course Overview
    2. ASP.NET Core SignalR Overview
    3. Basics
    4. Server Hubs
    5. HubContext
    6. Authorization
    7. Scaling with Redis
    8. Scaling with Azure SignalR Service

Source Code

All of the source code for this blog post and this course is available the Practical.AspNetCore.SignalR repo on GitHub.

Leave a Reply

Your email address will not be published. Required fields are marked *