Aspnetcore: Get List Of Connections in hub with usermapping system signalr core

Created on 23 Dec 2018  路  12Comments  路  Source: dotnet/aspnetcore

im using asp.net core 2.2 signalr and i use the usermappings and iuserprovider for user mapping in my project

how i can get the list of all connected users in usermappings system witout any dictionaries or list in memory ?

for example like this ??!?!?!

iHubContext.getAllConnectedUsers();

or ?!?!?!

iHubContext.Users.toList();

area-signalr

Most helpful comment

I would also appreciate access to the list of connected users to my hub. Especially from HubContext.

All 12 comments

how i can get the list of all connected users in usermappings system witout any dictionaries or list in memory?

You have to maintain the list yourself, SignalR does not provide a list.

I would also appreciate access to the list of connected users to my hub. Especially from HubContext.

@aliedp @devmonte I think it's a bad idea to get all individual users from SignalR itself when scaled out with Redis. Better maintain it with an external store, probably sharing the same Redis cache.

@wegylexy Hm maybe you are right. I haven't had yet opportunity to work with Redis :)

@wegylexy Correct me if I'm wrong, but if you use Microsoft.AspNetCore.SignalR.Redis, SignalR saves the connections list to the Redis server you specify in the configuration. Meaning, if the web server was scaled out, all SignalR nodes still share the same Redis server data.

So how is scaling out SignalR a problem? and if it is a problem, why not let the user worry about that and at least give him access to the basic list already saved somewhere?

@nour-s My understanding is that SignalR does NOT save the connections on Redis. It publishes messages to Redis channels, and subscribes to some channels for directly connected clients. Nothing persists on Redis. This is how it scales out, by not maintaining connections at any centralized place but distributing.

@wegylexy Hmmm, interesting, so basically, still each server has its own list of connections in the memory, but it gets updates from Redis published by other nodes, and pushes updates to other nodes?

@nour-s did you get your answer, please? I also have same issue, get connection id list on my controller, and based on the list do some actions.

Thanks,

@nour-s did you get your answer, please? I also have same issue, get connection id list on my controller, and based on the list do some actions.

Thanks,

@tarim
Apparently it is not gonna be soon to get that list, so I used ConcurrentDictionary to persist every connection when connected, and removing it from the list when disconnected. I also saved that list in Redis manually whenever a connection is added/deleted so all other web servers can read the same list.

Not ideal, but it does the job so far.

I have the same problem. Any updates? the list of connection ids in cache is extremely dangerous in case of concurrency.

We have logic tied to the list of currently active connections within a given Hub, which cannot be ported to .Net core and therefore the whole project has to remain on the full framework, due to this breaking change. In previous version heartBeat.GetConnections() used to work, but it doesn't exist any more.

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

Was this page helpful?
0 / 5 - 0 ratings