Message forwarding

Component: NServiceBus
NuGet Package NServiceBus (4.x)
Standard support for version 4.x of NServiceBus has expired. For more information see our Support Policy.

Use this feature to forward successfully processed messages from an endpoint to a specified 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.

Auditing vs Fowarding

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

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

Some of the audit message headers are available

Configuring Message Forwarding

Using app.config

<configuration>
  <configSections>
    <section name="UnicastBusConfig"
             type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
  </configSections>
  <UnicastBusConfig ForwardReceivedMessagesTo="destinationQueue@machine" />
</configuration>

Using IProvideConfiguration

class ProvideConfigurationForMessageForwarding :
    IProvideConfiguration<UnicastBusConfig>
{
    public UnicastBusConfig GetConfiguration()
    {
        return new UnicastBusConfig
        {
            ForwardReceivedMessagesTo = "destinationQueue@machine"
        };
    }
}

Using IConfigurationSource

public class ConfigurationSource :
    IConfigurationSource
{
    public T GetConfiguration<T>() where T : class, new()
    {
        if (typeof(T) == typeof(UnicastBusConfig))
        {
            var config = new UnicastBusConfig
            {
                ForwardReceivedMessagesTo = "destinationQueue@machine"
            };

            return config as T;
        }

        // Respect app.config for other sections not defined in this method
        return ConfigurationManager.GetSection(typeof(T).Name) as T;
    }
}

Initialize the Configuration Source as follows:

configure.CustomConfigurationSource(new ConfigurationSource());

Related Articles

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

Last modified