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
或者,如果您想让消息按特定顺序通过处理程序,请查看此链接:
关于.net - NServiceBus 消息拦截?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3897077/