title | summary | component | reviewed | redirects | related | |||
---|---|---|---|---|---|---|---|---|
Message Mutators |
Message Mutators allow mutation of messages in the pipeline |
Core |
2024-09-22 |
|
|
Message mutators allow mutation of messages in the pipeline.
NServiceBus supports two categories of message mutators:
Message mutators change/react to individual messages being sent or received. The IMutateOutgoingMessages
or IMutateIncomingMessages
interfaces allow the implementation of hooks for the sending and receiving sides.
Mutators can be used to perform actions such as validation of outgoing/incoming messages.
snippet: IMutateIncomingMessages
snippet: IMutateOutgoingMessages
Transport message mutators work on the serialized transport message and are useful for compression, header manipulation, etc.
Create transport message mutators by implementing the IMutateIncomingTransportMessages
or IMutateOutgoingTransportMessages
interfaces.
snippet: IMutateIncomingTransportMessages
snippet: IMutateOutgoingTransportMessages
Mutators are registered using:
snippet: MutatorRegistration
Note
Mutators are non-deterministic in terms of order of execution. If more fine-grained control is required over the pipeline see Pipeline Introduction.
If an incoming mutator throws an exception, the message aborts, rolls back to the queue, and recoverability is applied.
If an outgoing mutator throws an exception, the exception bubbles up to the method performing the Send or Publish. If the operation is performed on a context in the pipeline the message aborts, rolls back to the queue, and recoverability is applied. If the operation is performed on the message session the exception might bubble up to the user code or tear down the application domain if not properly handled.
include: non-null-task
include: mutators-versus-behaviors