我正在使用JavaScript SignalR客户端和.NET SignalR服务器应用程序。在Octopus Deploy重新部署应用程序后,客户端会停止接收来自服务器的任何消息,尽管服务器会从客户端接收消息并尝试发回消息。
更详细的行为:
在应用程序日志中重新启动服务器后,我看到服务器收到来自客户端的消息,但我没有看到该连接已创建。 我应该在重启后手动创建SignalR连接吗? 是否可以在没有创建连接的情况下接收来自客户端的消息?
以下是我用于记录的模块:
public class LoggingPipelineModule : HubPipelineModule
{
protected override void OnIncomingError(ExceptionContext exceptionContext, IHubIncomingInvokerContext invokerContext)
{
Logging.Logger.Error(exceptionContext.Error.Message, exceptionContext.Error);
base.OnIncomingError(exceptionContext, invokerContext);
}
protected override bool OnBeforeIncoming(IHubIncomingInvokerContext context)
{
Logging.Logger.Debug(string.Format(
"Invoking '{0}' on server hub '{1}' with connection id '{2}'",
context.MethodDescriptor.Name,
context.MethodDescriptor.Hub.Name,
context.Hub.Context.ConnectionId));
return base.OnBeforeIncoming(context);
}
protected override bool OnBeforeOutgoing(IHubOutgoingInvokerContext context)
{
var connection = context.Connection as Connection;
if (connection != null)
{
Logging.Logger.Debug(string.Format(
"Invoking '{0}' on client hub '{1}' with connection id '{2}'",
context.Invocation.Method,
context.Invocation.Hub,
connection.Identity));
}
else
{
Logging.Logger.Debug(string.Format(
"Invoking '{0}' on client hub '{1}'",
context.Invocation.Method,
context.Invocation.Hub));
}
return base.OnBeforeOutgoing(context);
}
protected override void OnAfterConnect(IHub hub)
{
Logging.Logger.Debug(string.Format("New connection with id {0} is established", hub.Context.ConnectionId));
base.OnAfterConnect(hub);
}
protected override void OnAfterDisconnect(IHub hub, bool stopCalled)
{
Logging.Logger.Debug(string.Format("Connection with id {0} was closed", hub.Context.ConnectionId));
base.OnAfterDisconnect(hub, stopCalled);
}
protected override void OnAfterReconnect(IHub hub)
{
Logging.Logger.Debug(string.Format("Connection with id {0} was recreated", hub.Context.ConnectionId));
base.OnAfterReconnect(hub);
}
}
以下是应用程序日志(没有创建连接):
2017-03-28 08:40:58,915 [62] DEBUG Invoking 'Push' on client hub 'ServerHub' with connection id '5dd083cc-f7fe-4b7d-8cae-d0e87b35d51c'
2017-03-28 08:41:18,213 [88] DEBUG Invoking 'Unsubscribe' on server hub 'ServerHub' with connection id '5dd083cc-f7fe-4b7d-8cae-d0e87b35d51c'
2017-03-28 08:41:18,447 [64] DEBUG Invoking 'Subscribe' on server hub 'ServerHub' with connection id '5dd083cc-f7fe-4b7d-8cae-d0e87b35d51c'
2017-03-28 08:41:23,916 [64] DEBUG Invoking 'Unsubscribe' on server hub 'ServerHub' with connection id '5dd083cc-f7fe-4b7d-8cae-d0e87b35d51c'
2017-03-28 08:41:24,151 [62] DEBUG Invoking 'Subscribe' on server hub 'ServerHub' with connection id '5dd083cc-f7fe-4b7d-8cae-d0e87b35d51c'