[英]How do I hook into NServiceBus to write to a log file when a message is transferred to the error queue?
We are currently using self-hosted NServiceBus to handle queuable messages in our system. 我们目前正在使用自托管的NServiceBus来处理系统中的排队消息。 Right now there are instances where a queued message might fail on the first try and work on the automatic retries.
现在,在某些情况下,排队的消息可能会在第一次尝试时失败,并且无法进行自动重试。
Right now we are logging on all failures, but we really don't care (at least for alerts) if a message failed the first time but worked on a re-try. 现在,我们正在记录所有失败,但是我们真的不在乎(至少对于警报而言)消息是否首次失败但可以重试。 What we do want to get alerted to is if all retries failed and a message goes into the error queue.
我们想要引起警报的是,如果所有重试均失败并且一条消息进入了错误队列。
Is there any way native to NServiceBus to have code run when it's moving a message to the error queue? 将消息移到错误队列时,NServiceBus是否有本机运行代码的方法?
If you are using the rest of the Service Platform (and you should!) that means that your error queue will have ServiceControl sitting on top of it, reading messages out of error and audit and persisting the details to its database so that it can serve up that information via its REST API to ServicePulse (for monitoring system health and uptime) and ServiceInsight (for exploration and debugging.) 如果您正在使用服务平台的其余部分(应该使用!),这意味着您的错误队列中将有ServiceControl位于其顶部,从错误中读取消息并进行审核,并将详细信息持久保存在其数据库中,以便可以使用通过其REST API将这些信息添加到ServicePulse (用于监视系统运行状况和正常运行时间)和ServiceInsight (用于探索和调试)。
Assuming you are using ServiceControl, it's pretty easy to have an endpoint subscribe to MessageFailed events that are published by ServiceControl. 假设您正在使用ServiceControl,让端点订阅由ServiceControl发布的MessageFailed事件非常容易。 I explained how to do it in my blog post Failed Message Notification with ServiceControl .
我在我的博客文章ServiceControl中的失败消息通知中解释了如何执行此操作。
This way, each endpoint doesn't have to be responsible for this task, and it is accomplished asynchronously by a centralized error monitoring endpoint. 这样,每个端点都不必负责此任务,它可以通过集中式错误监视端点异步完成。
It appears the correct way to do this is to create a custom implementation of IManageMessageFailures
and registering the custom fault manager curing configuration time. 看来,执行此操作的正确方法是创建
IManageMessageFailures
的自定义实现,并注册自定义的故障管理器固化配置时间。
An example of this is: 例如:
public class CustomFaultManager : IManageMessageFailures
{
private readonly IManageMessageFailures faultManager;
static CustomFaultManager()
{
Configure.Instance.MessageForwardingInCaseOfFault();
}
public CustomFaultManager()
{
faultManager = new FaultManager();
((FaultManager)faultManager).ErrorQueue = ConfigureFaultsForwarder.ErrorQueue;
}
void IManageMessageFailures.SerializationFailedForMessage(TransportMessage message, Exception e)
{
faultManager.SerializationFailedForMessage(message, e);
}
void IManageMessageFailures.ProcessingAlwaysFailsForMessage(TransportMessage message, Exception e)
{
faultManager.ProcessingAlwaysFailsForMessage(message, e);
//Custom code goes here
}
void IManageMessageFailures.Init(Address address)
{
faultManager.Init(address);
}
}
from https://github.com/Particular/NServiceBus/issues/463 来自https://github.com/Particular/NServiceBus/issues/463
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.