简体   繁体   English

当消息传输到错误队列时,如何挂接到NServiceBus以写入日志文件?

[英]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.

相关问题 如何引发强制将消息发送到NServiceBus中的错误队列的异常 - How to throw an exception that forces message to error queue in NServiceBus 如何在NServiceBus中正确合并多个消息? - How do I correctly pool multiple message in NServiceBus? NServiceBus - 如何为每个接收者订阅的消息类型获取单独的队列? - NServiceBus - How to get separate queue for each message type receiver subscribes to? 如何在不锁定队列的情况下通过NServiceBus发送大量消息? - How do I send lots of messages over NServiceBus without locking the Queue? 如何设置消息队列的所有者? - How do I set the owner of a message queue? 在 Unity 中,当我编写 Debug.Log(“ ”) 时出现错误,提示 UnityEngine.Log 和 System.Log 之间存在差异。 我该如何解决? - In Unity when I write Debug.Log(“ ”) it has an error saying that there is a difference between UnityEngine.Log and System.Log. How do I fix this? 使用NserviceBus.Test在未通过消息处理程序启动代码时如何测试发布的事件 - Using NserviceBus.Testing how do you test the published event when the code is not initiated via a message handler 托管在Azure上时如何控制NServiceBus队列名称? - How to control NServiceBus queue name when hosted on Azure? 无论设置了哪个级别,如何将行写到log4net日志文件? - How do I write a line to a log4net log file, regardless which level is set? 我可以在日志文件中写断言消息吗? - Can I write Assert message in my log file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM