Getting Started
Transports
Persistence
ServiceInsight
ServicePulse
ServiceControl
Monitoring
Previews
Samples

Message forwarding

Component: NServiceBus
NuGet Package: NServiceBus (7.x - 7.1)

Use this feature to forward successfully processed messages from an endpoint to a specific destination endpoint. Forwarding messages is particularly useful in complex upgrade scenarios when the old version and new version of a particular endpoint are running side-by-side.

Message processing abortion

Forwarding should not be used to abort message processing. Messages cannot be forwarded to the error queue as the required metadata for failed messages would not be present in the forwarded message's metadata. Attempting to use forwarding as a mechanism to abort processing can result in partial updates.

To abort processing throw an exception in the message handler. This ensures that no ghost message are transmitted and any transactional state changes are rolled back.

To prevent unnecessary retries declare an unrecoverable exception or create a custom recoverability policy.

Auditing vs. Forwarding

Auditing and Forwarding are very similar. Both send a copy of the processed message to another queue. The main difference is the intended usage scenarios.

Auditing is used for collecting information on what is happening in the system. The audited message is enriched with additional information regarding the processing of it. Forwarding would send a copy of the processed message without the additional auditing information.

The forwarded messages do not contain the audit message headers.

Configuring Message Forwarding

The ForwardReceivedMessagesTo attribute in the UnicastBusConfig configuration section is no longer supported starting from Version 6. Switch to the code first API when using Version 6 and above.

Using Code

endpointConfiguration.ForwardReceivedMessagesTo("destinationQueue@machine");

Forwarding a message from the handler

Individual messages can be forwarded directly from the handler:

await context.ForwardCurrentMessageTo("destinationQueue@machine")
    .ConfigureAwait(false);

Related Articles

  • Auditing Messages
    Configure where to send messages and it provides built-in message auditing for every endpoint.

Last modified