Reputation: 1782
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).
Upvotes: 3
Views: 1485
Reputation: 5273
NServiceBus now has a wide range of extensibility options for the message handling pipeline see https://docs.particular.net/nservicebus/pipeline/ for more details
Upvotes: 1
Reputation: 326
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:
Upvotes: 1