locked
SignalR: sending message to Users vs sending message to Groups RRS feed

  • Question

  • User-114320307 posted

    Hello,

    We use SignalR (v. 2.2.2.0) in our application. And there (starting from v.2.0.0) was added the possibility to send the messages to specific user or users:

    var context = GlobalHost.ConnectionManager.GetHubContext();
    var userIds = new List<string>{...};
    context.Clients.Users(userIds).doSomethingOnTheClient(...); 

    And the other possibility is to send message to specific group. I mean:

    var context = GlobalHost.ConnectionManager.GetHubContext();
    string groupName = "..."; context.Clients.Group(groupName).doSomethingOnTheClient(...);

    We have some consideration about the sending messages to the Users instead of Groups.

    Besides I would like to add we use Redis scaleout.

    Could someone explain the difference between usage of these two approaches?

    How it works under the hood? Which approach is better?

    Thanks in advance.

    Kind regards,

    Taras K.

    Wednesday, May 2, 2018 2:50 PM

All replies

  • User61956409 posted

    Hi Taras,

    Both approaches that you mentioned can be used to send messages to specified subsets of connected clients. Let’s consider these specifical scenarios:

    If you’d like to send messages to too many connected clients, using Clients.Users(userIds), you need to pass all client Ids to that method manually. for this scenario, using Clients.Group(groupName) would be more easy and convenient.

    On the other hand, if you send messages to users in a specified group except the specified clients, and these specified clients (you do not want them see messages) are also too many, in this scenario, using Clients.Group(groupName, excludeConnectionIds) maybe not more convenient than using Clients.Users(userIds).

    Briefly, using Clients.Users(userIds) or Clients.Group(groupName) depend on your specified scenarios, and both of these two methods can help you send messages to specified subsets of connected clients.

    With Regards,

    Fei Han

    Thursday, May 3, 2018 8:52 AM
  • User-114320307 posted

    Hello,

    Thank you so much for so quick answer.

    Let me ask you some additional questions.

    What about performance and memory resources? If we want to send message to multiple clients.

    Which approach (sending to Users or sending to Group) is better in this case (taking into the consideration the performance and memory usage and scale out)?

    Thank you so much in advance.

    My kind regards,

    Taras K.

    Thursday, May 3, 2018 10:06 AM
  • User61956409 posted

    Hi Taras,

    What about performance and memory resources? If we want to send message to multiple clients.

    I did not test and compare the differences of the performance and memory usage of using Clients.Users(userIds) and Clients.Group(groupName) with many client connections in production environment, but if you’d like to trace the actual performance and memory usage while using these two methods, the performance counters could help you collect the useful data.

    With Regards,

    Fei Han

    Tuesday, May 8, 2018 5:50 AM