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 继承代码>类)。
Is there any way to intercept messages in NServiceBus?
From now i can do it manually via introducing base message handler like this:
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
}
}
And the usage:
public class ConcreteMessageHandler : MessageHandler<ConcreteMessage>
{
protected override void HandleCommand(ConcreteMessage message)
{
//handle command
}
}
But doing this way i'm loosing an ability to subscribe to multiple messages (because i cannot inherit from multiple MessageHandler<>
classes).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您使用的是NServiceBus V3,您可以查看IMutateOutgoingMessages和IMutateIncomingMessages接口。
http://support.nservicebus.com/customer/portal /articles/894155-nservicebus-message-mutators-sample
或者,如果您想让消息按特定顺序通过处理程序,请查看此链接:
http://support.nservicebus.com/customer /portal/articles/862397-如何指定调用处理程序的顺序-
If you are using NServiceBus V3, you can take a look at the IMutateOutgoingMessages and IMutateIncomingMessages interfaces.
http://support.nservicebus.com/customer/portal/articles/894155-nservicebus-message-mutators-sample
Or if you want to have the messages go through handlers in a specific order, check out this link:
http://support.nservicebus.com/customer/portal/articles/862397-how-do-i-specify-the-order-in-which-handlers-are-invoked-
NServiceBus 现在为消息处理管道提供了广泛的可扩展性选项,请参阅 https://docs.pspecial。 net/nservicebus/pipeline/ 了解更多详细信息
NServiceBus now has a wide range of extensibility options for the message handling pipeline see https://docs.particular.net/nservicebus/pipeline/ for more details