Azure / azure-signalr

Azure SignalR Service SDK for .NET

Home Page:https://aka.ms/signalr-service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mixing Default Mode with legacy aspnet Signalr and groups with REST api

odewdney opened this issue · comments

Describe the issue

I am trying to migrate a legacy ASP.NET SignalR app to Azure SignalR. The Web App (.net v4.7.2) hosting the signalr endpoint and hub and the web client work fine together, but I am trying to inject Broadcast message to a Group using the REST api ( v1 or 2022-06-01) from a Console App.

The excerpt from the Live Trace Log from the Azure signalr service shows the comms:

EventName Message Hub ConnectionId URL
ConnectionStarted ConnectionStarted VO-VVGpyu1lq0sKu9B3hWAbmEPjwd02
ReceivedMessageFromServer Received a JoinGroupWithAckMessage message [855212887252140039] from server connection V-Jk_J0NWQ58361MwEIVVQbmEPjwd02. aspnet-signalr-appname_appname V-Jk_J0NWQ58361MwEIVVQbmEPjwd02
AddedConnectionToGroup Added connection VO-VVGpyu1lq0sKu9B3hWAbmEPjwd02 to group hg-HubName.GroupName via message [855212887252140039] successfully. VO-VVGpyu1lq0sKu9B3hWAbmEPjwd02
ReceivedMessageFromServer Received a GroupBroadcastDataMessage message [855212887252140045] from server connection V-Jk_J0NWQ58361MwEIVVQbmEPjwd02. aspnet-signalr-appname_appname V-Jk_J0NWQ58361MwEIVVQbmEPjwd02
SentMessageToClient Sent a message [855212887252140045] to client connection VO-VVGpyu1lq0sKu9B3hWAbmEPjwd02 successfully. aspnet-signalr-appname_appname VO-VVGpyu1lq0sKu9B3hWAbmEPjwd02
ReceivedMessageFromRestApi Received a message [1023305194114383872] from REST API: POST api/hubs/{hub}/groups/{group}/:send. hubname
NoConnectionInGroup Group message [1023305194114383872] was not received because there's no active connection in group [hg-HubName.GroupName].
ProcessedMessageFromRestApi Processed a message [1023305194114383872] from REST API: POST api/hubs/{hub}/groups/{group}/:send. hubname
RequestProcessed RequestProcessed https://servicename.service.signalr.net/api/hubs/hubname/groups/hg-HubName.GroupName/:send?api-version=2022-06-01

appname, hubname, HubName, GroupName replaced to protect the innocent.

The Log shows the Client connecting, The client makes a call to the Hub, which adds the connection to a group. The hub successfully sends a message to the group, and the message is processed by the client. But when the REST api tries to use the same group name the log reports that there are no members of the group.

Its seems the ASP.NET signalr layer is creating a hub/app with an underscore in its name. I cannot use this hub name as it fail the API validation and I get a 400 error in the REST call.

I have tried setting up part of the server side ASP.NET/Azure-SignalR server code in the Console App, but it seems to try to send new client connection requests down the websocket connection, which the console app is not in a position to process.

What is the purpose of the Application name in the ASP.NET Azure owin AppBuilder.RunAzureSignalR call?

Is there a way of injecting outbound messages when using ASP.NET SignalR

Frameworks:
package id="Microsoft.Azure.SignalR.AspNet" version="1.21.5" targetFramework="net472"

Answering one of my questions - App name - seems to be used to create internal hub names when supplied in the API - with $"{appname}_{hubname}" - but there seems to be an inconsistency in the API - the server/websocket API allows underscores and dashes, where the REST API only allows underscores. Not sure this is a good choice given the join character in the meta hub name is an underscore giving possible ambiguity.

Would allowing dashes for app names ( and hub names? ) in the REST api solve my issue - allowing me to set the application name to "aspnet-signalr-appname?

@odewdney , rest api do not work for aspnet signalr, it is only for aspnet core signalr.
see: this note in this docuemnt

Thanks for that documentation link. I have worked around the problem with
serviceOptions.ServerStickyMode = ServerStickyMode.Required;
so my none web facing app can connect to the SignalR service without getting user calls.

I was wondering if this is a technical limitation, or just unsupported, that is blocked by the hub naming restriction. I guess its down to the legacy asp.net signalr inter-op layer.

This is exactly the problem I have been chasing all day today. It seems that the asp.net signal library is prefixing the name of the hub and when I try to reuse that name in another app (an azure function), they are not the same names. Trying to set the names to be the same doesn't work due to the naming restrictions. Stuck for the moment.

@odewdney @m1dst
AspNet SignalR and AspNet Core SignalR are using different protocols, they are not compatible.
REST API in Azure SignalR service can only generate the messages for AspNet Core SignalR.
And there is no plan to support AspNet SignalR for REST API.