0

Problem: To minimize per-message charges, I'd like to restrict messages by method name. Per the picture below, I need to know to which clients SignalR will send a message in the following case:

1.) Create Hub "/MyHub"

2.) 3 users (on Angular clients) register with the Hub, with a method named "Post_A"

3.) Then 2 different users register with the same Hub with a method named "Post_B"

4.) If the API server sends an update via Clients.All.SendAsync("post_B", dto) will it only go to users 3 & 4? Or will that message go to all five users?

Bonus! If the answer is that all messages go to all users, is there an option without using groups? I don't think groups will work w/o a lot of additional overhead each time a user views a new post (there will be thousands of posts).

Thank you!

enter image description here

Jason
  • 396
  • 1
  • 3
  • 17
  • Why using groups is a problem for you? They exists exactly to cases like yours... Microsoft even recommend that you can have even 1 user per group... – Kiril1512 Oct 18 '20 at 13:52
  • I think it would add unnecessary load on my API. Unnecessary, that is, if #4 above is correct. – Jason Oct 19 '20 at 21:18
  • In order to route messages, you'll can store connectionId's in some form of static dictionary or list (if you want to cache them, you can use redis), then you can send a message to that dictionary/list if you want. – Rav Oct 20 '20 at 16:27
  • Thanks @Rav. That doesn't really work w/ my current architecture, but might be useful later. – Jason Oct 21 '20 at 21:22

1 Answers1

0

Did some testing.

SignalR's Clients.All.SendAsync(MethodName, object) does send a message to all clients, even if they haven't registered with the method MethodName.

enter image description here

As you can see in the client-side logs above (after turning on SignalR's logging to console), the client throws a warning when it receives a message for which it has no method registered.

So groups are the only option for restricting messages.

Jason
  • 396
  • 1
  • 3
  • 17