gpt4 book ai didi

SignalR(原始)不向客户端发送消息

转载 作者:行者123 更新时间:2023-12-02 15:39:52 26 4
gpt4 key购买 nike

我们正在使用 SignalR(原始版本,而不是 Core 版本)并注意到一些无法解释的行为。我们的情况如下:

  1. 我们有一个通过 GenericCommand() 方法接受命令的集线器(见下文)。
  2. 这些命令使用 NServiceBus 放置在消息总线上
  3. 命令的执行会产生一个事件
  4. 事件处理程序会向所有 SignalR 客户端发送一条消息(见下文)

使用 Chrome 中的调试器工具查看 Websocket 消息,很明显,有时(但并非总是)“InvokeToAll”消息永远不会发送到任何客户端。不会引发任何错误,所有连接的客户端仅发送心跳信号,表明它们仍然处于连接状态。

此外,服务器上的跟踪(见下文)日志表明连接始终处于事件状态,但由于某种原因,立即从集线器发送的三个测试“已接收”消息被发送回客户端,但由于某种原因,从事件处理程序发送的结果“InvokeToAll”并未使用 Websocket 发送。我们知道事件处理程序被调用,因为 _notificationService.MarkAsDone() 调用在数据库中留下了确认其被调用的痕迹。

我们注意到的最后一件事是,此设置一直有效,直到不起作用为止。一旦消息停止发送到客户端,所有客户端的消息就会始终停止。我们完全不知道可能发生什么,或者我们还能做些什么来进一步调试这个问题。不会抛出任何错误,并且正常工作的东西会突然停止工作,恕不另行通知...

任何帮助或指示将不胜感激。

以下是 Hub 的代码(第 1 步):

public async Task GenericCommand(GenericEventData data) {
await _messageBus.PublishEvent(new GenericSignalrCommandReceivedEvent {
CorrelationId = Guid.Parse(data.CorrelationId),
Command = data.Command,
DataJson = data.DataJson,
ConnectionId = Context.ConnectionId
});

// Added for debugging purposes
var ctx = GlobalHost.ConnectionManager.GetHubContext<EventHub>();
IClientProxy proxy = ctx.Clients.Client(Context.ConnectionId);
await proxy.Invoke(data.CorrelationId, "Received - ConnectionId");

proxy = ctx.Clients.User(Context.User.Identity.Name);
await proxy.Invoke(data.CorrelationId, "Received - Clients.User");
proxy = ctx.Clients.Group("JCUSER:" + Context.User.Identity.Name);
await proxy.Invoke(data.CorrelationId, "Received - Clients.Group");
}

这是事件处理程序的代码(第 4 步)

private async Task ReplyViaSignalR(SignalrCompletedData data, IMessageHandlerContext context) {
var ctx = GlobalHost.ConnectionManager.GetHubContext<EventHub>();
var proxy = ctx.Clients.All;
await proxy.Invoke("InvokeToAll", "Yay message received!");
await _notificationService.MarkAsDone(data);
}

以下是服务器上此客户端连接的跟踪日志的摘录:

SignalR.Transports.TransportHeartBeat Information: 0 : Connection 1d603a67-1161-4a27-82f0-9046ec73cd60 is New.
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,15|rS,0|pP,A|rT,1","S":1,"M":[]}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,15|rS,0|pP,A|rT,2|pR,1E","G":"F2q+KKxufchVxQUnH9leeyYR6fGPfHYRCIQW55XZbNEbbibRlbVYld/b0fzihC34VrDwmoaNy2uTJYnRCeQO9zGEoqNk+9qbAi72dPep52CgpicyPGQOlvNzUOlNK1v2j34SdPXHI8DwpDwx/7SA317XJMJPxrCE5Qsgt/kgTzE=","M":[]}
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,1F|rS,5|pP,19|rT,2|pR,43","M":[{"H":"EventHub","M":"a1ec2fa6-f33c-4161-9166-07ee64558be1","A":["Received - ConnectionId"]},{"H":"EventHub","M":"a1ec2fa6-f33c-4161-9166-07ee64558be1","A":["Received - Clients.User"]}]}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,1F|rS,5|pP,19|rT,2|pR,44","M":[{"H":"EventHub","M":"a1ec2fa6-f33c-4161-9166-07ee64558be1","A":["Received - Clients.Group"]}]}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"I":"4"}
SignalR.Transports.WebSocketTransport Verbose: 0 : Sending outgoing message. Connection id: 1d603a67-1161-4a27-82f0-9046ec73cd60, transport: WebSocketTransport, message: {"C":"d-498F7600-B,1F|rS,5|pP,19|rT,2|pR,45","M":[]}
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)
SignalR.Transports.TransportHeartBeat Verbose: 0 : KeepAlive(1d603a67-1161-4a27-82f0-9046ec73cd60)

最佳答案

事实证明,这个问题是由于我们在同一应用程序池中有多个站点使用不同的主机名指向同一目录而引起的。

这导致应用程序运行该站点的多个并发实例,尽管只显示一个 w3wp.exe 进程(我们正是通过这种方式消除了同时运行多个实例的可能性)。

我们计划在有机会时通过简单地将绑定(bind)组合到同一网站实例来改变这种情况。我完全希望问题能够得到解决。

关于SignalR(原始)不向客户端发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58756307/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com