0

Our Azure SignalR application is a bit of a hybrid, outgoing messages go into ActiveMQ then get picked up by a listener in a hosted service that receives them and sends them to the NotificationsHub (in the same API project). e.g. await _notificationsHub.Clients.All.SendAsync("PerformAction", action, payload);

Recently I tried to extend this so that a second application using a different authentication scheme (this one is external facing, the existing one is internal facing) could connect and receive some messages (and send others back). I did a POC and everything seemed fine.

public class NotificationsHub : Microsoft.AspNetCore.SignalR.Hub {
  public override async Task OnConnectedAsync() {
    await Groups.AddToGroupAsync(Context.ConnectionId, "foo");
    await base.OnConnectedAsync();
    await Clients.Caller.SendAsync("SetConnectionId", Context.ConnectionId);
 }
}

Today I was debugging in Visual Studio the new application API and in the Hub's OnConnectedAsync method I kept receiving the "connected" events for users on a completely different server.

So my question is, does SignalR fire the "OnConnected" event for every hub connected to the same endpoint (for every instance of that hub)?

Even if that is the case wouldnt these two Hub classes be considered separate and not share their groups (see multiple hubs)?

Edit

For reference the project is targeting netcoreapp3.1, and using Microsoft.Azure.Signalr 1.8.1 in the original project and 1.16.1 in the new one.

gamelover42
  • 355
  • 1
  • 3
  • 15
  • Why do you think the connections are also on a different server? Are both your servers using the same Azure SignalR instance and have the same hub name? Then you're probably getting some new connections on the new server and some on the old server. – Brennan Apr 29 '22 at 05:12
  • I was debugging with a breakpoint in OnConnectedAsync, and the Context.User was a user a different user. My machine does not allow incoming external connections. And yes. the development server and my workstation were both using the same azure signalr endpoint. – gamelover42 Apr 29 '22 at 23:26
  • 1
    "My machine does not allow incoming external connections" - Azure SignalR works differently, the incoming connections actually are coming over WebSocket connections that your machine made to Azure SignalR, so it's not real physical connections, they're muxed over the WebSocket connections you made. If you are set on using the same azure signalr endpoint but don't want conflicts, there is an ApplicationName setting on the server which should allow you to have different apps without conflicts. – Brennan Apr 30 '22 at 00:59

1 Answers1

0

It turns out that SignalR uses the name of the "Hub" class when connecting to the Azure SignalR service, i.e. 'wss://foo.service.signalr.net/server/?hub=notificationshub&cid={guid}'.

All hubs with the same name are treated as the same hub. I couldnt find that in the docs anywhere but it is implied in ApplicationName property of ServiceOptions which says "Gets applicationName, which will be used as a prefix to apply to each hub name"

gamelover42
  • 355
  • 1
  • 3
  • 15