Configure immediate retries

Component: NServiceBus
NuGet Package NServiceBus (3.x)
Standard support for version 3.x of NServiceBus has expired. For more information see our Support Policy.
In order to get full control over Immediate Retries it is possible to override the default Recoverability Policy.
Immediate Retries cannot be used when transport transactions are disabled.

Configuring

  • MaxRetries: Number of times Immediate Retries are performed. Default: 5.

Using app.config

<configuration>
  <configSections>
    <section name="MsmqTransportConfig"
             type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
  </configSections>
  <MsmqTransportConfig MaxRetries="5"/>
</configuration>

Through IProvideConfiguration

class ProvideConfiguration :
    IProvideConfiguration<MsmqTransportConfig>
{
    public MsmqTransportConfig GetConfiguration()
    {
        return new MsmqTransportConfig
        {
            MaxRetries = 2
        };
    }
}

Through ConfigurationSource

public class ConfigurationSource :
    IConfigurationSource
{
    public T GetConfiguration<T>() where T : class, new()
    {
        if (typeof(T) == typeof(MsmqTransportConfig))
        {
            var config = new MsmqTransportConfig
            {
                MaxRetries = 2
            };

            return config as T;
        }

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

Disabling

Using app.config

<configuration>
  <configSections>
    <section name="MsmqTransportConfig"
             type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
  </configSections>
  <MsmqTransportConfig MaxRetries="0"/>
</configuration>

Through IProvideConfiguration

class DisableProvideConfiguration :
    IProvideConfiguration<MsmqTransportConfig>
{
    public MsmqTransportConfig GetConfiguration()
    {
        return new MsmqTransportConfig
        {
            MaxRetries = 0
        };
    }
}

Through ConfigurationSource

public class DisableConfigurationSource :
    IConfigurationSource
{
    public T GetConfiguration<T>() where T : class, new()
    {
        if (typeof(T) == typeof(MsmqTransportConfig))
        {
            var config = new MsmqTransportConfig
            {
                MaxRetries = 0
            };

            return config as T;
        }

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

Samples


Last modified