Web 应用程序订阅了事件,但不处理它们
我的 Web 进程向域发送命令并处理事件(通过 SIignalR 推送到浏览器)。它在 IIS Express / Win7 x64 上运行 ASP.NET MVC3 和 .NET 4
有时,有时从一开始,它就决定停止向我的处理程序分发事件。这些事件位于 Web 端点的日志队列中,但没有其他痕迹。它们完全从日志中丢失,处理程序中的断点从未被命中,并且端点和错误队列都是空的。
Func<Type, bool> isMessage = t => typeof(IMessage).IsAssignableFrom(t);
Func<Type, bool> isCommand = t => typeof(ICommand).IsAssignableFrom(t);
Func<Type, bool> isEvent = t => typeof(IEvent).IsAssignableFrom(t);
Configure.WithWeb()
.NinjectBuilder(Kernel)
.DefineEndpointName("Hospital.Web")
.DefiningMessagesAs(isMessage)
.DefiningCommandsAs(isCommand)
.DefiningEventsAs(isEvent)
.Log4Net()
.JsonSerializer()
.MsmqTransport()
.UnicastBus()
.LoadMessageHandlers()
.PurgeOnStartup(true)
.CreateBus()
.Start();
这是我的 web.config 的 NSB 部分:
<MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Hospital.Commands" Endpoint="Hospital.CommandHandlers" />
<add Messages="Hospital.Events" Endpoint="Hospital.CommandHandlers" />
</MessageEndpointMappings>
</UnicastBusConfig>
这是我的处理程序之一:
public class StatsHandler :
IHandleMessages<PatientAdmitted>,
IHandleMessages<BedAssigned>,
IHandleMessages<PatientDischarged>
{
private static readonly ILog Log = LogManager.GetLogger(typeof (StatsHandler));
private readonly IConnectionManager _connectionManager;
public StatsHandler(IConnectionManager connectionManager)
{
_connectionManager = connectionManager;
}
protected dynamic Clients
{
get { return _connectionManager.GetClients<StatsHub>(); }
}
public void Handle(PatientAdmitted message)
{
Log.DebugFormat("Admitted {0} {1}", message.FirstName, message.LastName);
Clients.patientAdmitted();
}
public void Handle(BedAssigned message)
{
Log.DebugFormat("Assigned {0} to {1}", message.PatientId, message.Bed);
Clients.bedAssigned();
}
public void Handle(PatientDischarged message)
{
Log.DebugFormat("Discharged {0}", message.PatientId);
Clients.patientDischarged();
}
}
我还 在NServiceBus群里问过这个问题。该消息附加了一个日志文件。
My web process sends commands to the domain and handles events (to push through SIgnalR to browsers). It's running ASP.NET MVC3 and .NET 4 on IIS Express / Win7 x64
At random, and sometimes right from the start, it decides to stop distributing events to my handlers. The events are in the web endpoint's journal queue, but there is no other trace of them. They're missing from the log entirely, my breakpoints in the handlers are never hit, and both the endpoint and the error queue are empty.
Func<Type, bool> isMessage = t => typeof(IMessage).IsAssignableFrom(t);
Func<Type, bool> isCommand = t => typeof(ICommand).IsAssignableFrom(t);
Func<Type, bool> isEvent = t => typeof(IEvent).IsAssignableFrom(t);
Configure.WithWeb()
.NinjectBuilder(Kernel)
.DefineEndpointName("Hospital.Web")
.DefiningMessagesAs(isMessage)
.DefiningCommandsAs(isCommand)
.DefiningEventsAs(isEvent)
.Log4Net()
.JsonSerializer()
.MsmqTransport()
.UnicastBus()
.LoadMessageHandlers()
.PurgeOnStartup(true)
.CreateBus()
.Start();
Here's the NSB parts of my web.config:
<MsmqTransportConfig ErrorQueue="error" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="Hospital.Commands" Endpoint="Hospital.CommandHandlers" />
<add Messages="Hospital.Events" Endpoint="Hospital.CommandHandlers" />
</MessageEndpointMappings>
</UnicastBusConfig>
Here's one of my handlers:
public class StatsHandler :
IHandleMessages<PatientAdmitted>,
IHandleMessages<BedAssigned>,
IHandleMessages<PatientDischarged>
{
private static readonly ILog Log = LogManager.GetLogger(typeof (StatsHandler));
private readonly IConnectionManager _connectionManager;
public StatsHandler(IConnectionManager connectionManager)
{
_connectionManager = connectionManager;
}
protected dynamic Clients
{
get { return _connectionManager.GetClients<StatsHub>(); }
}
public void Handle(PatientAdmitted message)
{
Log.DebugFormat("Admitted {0} {1}", message.FirstName, message.LastName);
Clients.patientAdmitted();
}
public void Handle(BedAssigned message)
{
Log.DebugFormat("Assigned {0} to {1}", message.PatientId, message.Bed);
Clients.bedAssigned();
}
public void Handle(PatientDischarged message)
{
Log.DebugFormat("Discharged {0}", message.PatientId);
Clients.patientDischarged();
}
}
I've also asked this question in the NServiceBus group. There's a log file attached to that message.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RC4 中的一个错误可能导致此行为,您可以尝试 RC5 看看是否有帮助?
There was a bug in RC4 that could have caused this behavior, can you try RC5 and see if that helps?