仅向连接到 SignalR 中 2 个不同集线器的特定组中的特定用户发送消息

Send message only to a specific user in a specific group connected to 2 different hubs in SignalR

如果我有以下连接用户的情况

`clientwebsiteA -> hubA -> groupA -> id:george@email.com`

`cliebtwebsiteB -> hubA -> groupB -> id:george@email.com`

用户 george 已连接登录到 2 个不同的网站客户端(同时),每个客户端都连接到信号器 hubA(注意:hub a 是单个 webapp,托管多个 hub)。

如果我只想向 hubA.groupA.id 发送消息:@george.email.com.
这可能吗?

或者如果我发送消息给

`clients.User("george@email.com")`

他会在他的两个连接上收到消息吗?

我希望看到像这样的方法 clients.Group("A").User("george@email.com").SayHello()

clients.UserInGroup("A",id:george@email.com").SayHello()

如果这不可能,如果我使用 2 个不同的集线器(有 2 条不同的路由)可以实现吗

M$ 表示多个集线器共享与信号服务器的相同连接。 https://docs.microsoft.com/en-us/aspnet/signalr/overview/guide-to-the-api/hubs-api-guide-server#multiplehubs

If I wanted to only send a message to hubA.groupA.id:@george.email.com. is this possible?

如果用户 george 从两个不同的客户端应用程序(clientwebsiteA 和 clientwebsiteB)连接到同一个中心服务器 (hubA),用户 george 将建立到中心服务器的两个连接(具有两个不同的 ConnectionId)。在这种情况下,要向该特定客户端用户 george(来自 clientwebsiteA)发送消息,您可以将用户映射到中心服务器上的连接(实现 user-site-connectionId 映射),这样您就可以根据用户和站点,然后使用 connectionId 向特定用户发送消息,如下所示。

await Clients.Client(connectionId_here).SendAsync("SayHello");

或者您可以实施和使用 single-user 组。

//join group while george connect from site A

await Groups.AddToGroupAsync(connectionId_here, "SiteAGroupAGeorge");

那么当您只想联系到该用户时,您可以向该组发送消息。

await Clients.Group("SiteAGroupAGeorge").SendAsync("SayHello");