.net - NServiceBus 消息拦截?

标签 .net nservicebus

NServiceBus中有什么方法可以拦截消息吗?

从现在开始,我可以通过引入这样的基本消息处理程序来手动完成此操作:

public abstract class MessageHandler<T> : IHandleMessages<T>
    where T : IMessage
{
    public IBus Bus { get; set; }

    protected abstract void HandleCommand(T command);

    public void Handle(T command)
    {
        // perform some logic on *command* before
        HandleCommand(command);
        // perform some logic on *command* after
    }
}

以及用法:

public class ConcreteMessageHandler : MessageHandler<ConcreteMessage>
{
    protected override void HandleCommand(ConcreteMessage message)
    {
        //handle command
    }
}

但这样做我失去了订阅多条消息的能力(因为我不能从多个 MessageHandler<> 类继承)。

最佳答案

如果您使用的是 NServiceBus V3,您可以查看 IMutateOutgoingMessages 和 IMutateIncomingMessages 接口(interface)。

http://support.nservicebus.com/customer/portal/articles/894155-nservicebus-message-mutators-sample

或者,如果您想让消息按特定顺序通过处理程序,请查看此链接:

http://support.nservicebus.com/customer/portal/articles/862397-how-do-i-specify-the-order-in-which-handlers-are-invoked-

关于.net - NServiceBus 消息拦截?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3897077/

相关文章:

.net - 在Visual Studio调试器值 "{ }"中是什么意思?

c# - .NET 将日期时间转换为格式可排序日期/时间模式 ("s");

c# - 将多行 JSON 反序列化为 C# 对象

c# - 实现自定义 JsonWriter (JSON.net)

nservicebus - Web 应用程序订阅了事件,但不处理它们

vb.net - 从另一个项目引用 NServiceBus 程序集时出现 "Reference required"错误

.net - F# JSON 类型提供程序 : Handling DateTime and TimeZone

c# - WCF 与服务总线

使用内存中的 NServiceBus 进行测试

c# - 容器不处理 transient 组件