Azure SignalR ApplicationName
Azure SignalR is a messaging technology that runs on the Azure infrastructure. It manages real-time websocket connections between clients and servers. The client (typically a browser) keeps open a websocket connection to the Microsoft SignalR server in order to send and receive messages.
Messages can be broadcast simultaneously to multiple clients, which makes the technology ideal for the AI chat sessions that we often see in browsers. The text chunks that are generated by the LLM (eg OpenAI GPT models) can be sent directly to the browser as they are generated. This creates a more customer friendly experience by being able to start reading the response before the full response has been generated.
Problem
When running Azure SignalR in a professional situation with multiple developers in a team I regularly encountered the following issue. Local development happens on a local computer and all of the team uses a single shared Azure SingalR instance. I experienced that messages became lost between the different developer machines.
What does this mean? In my case, we had a development environment that is always running and connected to a development Azure SignalR resource. When I ran the ASP.NET project locally, my local instance also connects to the same development Azure SignalR resource. I then have a web client which connects to the Azure SingalR resource via my local ASP.NET project with the intention of sending and receiving chat messages.
What often happens is that messages were never reaching my local ASP.NET service, they were being picked up instead in the development environment ASP.NET instance. During debugging sessions it would randomly cause a lot of wasted time when messages would not arrive to debug reliably.
Solution
After encountering the issue multiple times I investigated options for resolving this. It turns out that a configuration option called ApplicationName can be passed to the Azure SignalR resource when establishing the connection from the ASP.NET project to isolate messages between multiple applications that share the same SignalR resource.
This option can be useful when you want to share the same Azure SignalR instance for different app servers containing the same hub names. If not set, all the connected app servers are considered to be instances of the same application.
By passing the ApplicationName option with a unique name, the messages sent on that connection are guaranteed to come back to the same instance.
services.AddSignalR()
.AddAzureSignalR(options =>
{
options.ConnectionString = "<replace with your connection string>";
options.ApplicatioName = "my-unique-name";
});
With the ApplicationName option configured, the problem was resolved and a lot of debugging time was saved.
- Previous: Cloud Stats