Search code examples
signalrsignalr-hubsignalr.clientmsgpackazure-signalr

Using MessagePack protocol in the context of serverless Azure SignalR services


The following code works fine with my Azure SignalR Services (serverless mode) and I am able to receieve messages/events successfully.

var connection = new HubConnectionBuilder()
            .WithUrl(connectionInfo.NegotiationUrl!, options =>
            {
                options.Headers.Add("x-ms-signalr-userid", "myuserid");
                options.Headers.Add("x-functions-key", "mykey");
            })
            .WithAutomaticReconnect(new[] { TimeSpan.Zero, TimeSpan.Zero, TimeSpan.FromMilliseconds(5) })
            .Build();
        connection.Closed += excecption =>
        {
            return Task.CompletedTask;
        };
        connection.On("onMsg", (Action<object>)(message =>
        {
                    Console.WriteLine(message)
        }));

I referenced the .NET MessagePack NuGet package for SignalR and invoked .AddMessagePackProtocol() extension method in the hub connection builder per the code below but stop receiving messages from SignalR.

var connection = new HubConnectionBuilder()
            .WithUrl(connectionInfo.NegotiationUrl!, options =>
            {
                options.Headers.Add("x-ms-signalr-userid", "myuserid");
                options.Headers.Add("x-functions-key", "mykey");
            })
                        .AddMessagePackProtocol()
            .WithAutomaticReconnect(new[] { TimeSpan.Zero, TimeSpan.Zero, TimeSpan.FromMilliseconds(5) })
            .Build();

Am I missing anything in this configuration? What is the right approach to solve this problem? I don't think if we need to do anything on Azure SignalR Service configuration to start getting messagePack packets.

I expect to receive the signalR messages when the message pack protocol is enabled.


Solution

  • The chosen Azure signalR service transport type is Persistent, and the messagePack protocol is not supported in this mode per this article.