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

时间:2019-11-07 20:15:49

标签: signalr nservicebus

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

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

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

此外,服务器上的跟踪日志(请参见下文)表明该连接在整个时间内都处于活动状态,但是由于某种原因,立即将从集线器发送的三个测试“已接收”消息发送回客户端,但是由于某种原因,未使用Websocket发送事件处理程序发送的结果“ InvokeToAll”。我们知道事件处理程序被调用是因为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"); } 调用会在数据库中留下跟踪以确认它被调用。

我们注意到的最后一件事情是,该设置有效,直到无效为止。一旦消息停止发送给客户端,它就会一直对所有客户端停止。对于可能发生的事情或者我们可以做进一步调试的事情,我们完全不知所措。不会引发任何错误,并且某些正常工作会突然停止工作而不会发出通知...

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

这是集线器的代码(步骤1):

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);
}

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

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)

这是服务器上与该客户端连接的跟踪日志的摘录:

{{1}}

1 个答案:

答案 0 :(得分:0)

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

这导致该应用程序运行该站点的多个并发实例,尽管仅显示一个w3wp.exe进程(这是我们为了消除同时运行多个实例的可能性而观察的结果)。

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