SignalR groups - filtering handled on client or se

2019-03-24 14:34发布

I've been reading a decent amount regarding SignalR hubs and groups. In particular, I've noticed that you cannot get a count of the connections in a particular group.

Is the filtering for groups handled on the client or server? If the server, why can't SignalR expose a count? If on the client, is there a way to send messages only to particular clients?

1条回答
对你真心纯属浪费
2楼-- · 2019-03-24 15:13

When you send a message to a particular group of specific connection, filtering happens on the server (there's no filtering, you're just addressing that one connection or group).

SignalR is based on pub sub so there's no list of connections per se. If you want to keep track of a list of connections then you have to handle the connection and disconnect events and persist them in memory or some persistent storage.

The reason we don't give you a list of connections is because any state we store hurts scaling out across nodes. If we gave you a list of connections, it's a pit of failure, because if you add another web node to your farm, you suddenly have to synchronize state across it. We let you address individual connections or groups via their identifier and that allows us to use the message bus to publish to all subscribers of that identifier.

查看更多
登录 后发表回答