Configure immediate retries

Component: NServiceBus
NuGet Package NServiceBus (5.x)
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="TransportConfig"
             type="NServiceBus.Config.TransportConfig, NServiceBus.Core"/>
  </configSections>
  <TransportConfig MaxRetries="2" />
</configuration>

Through IProvideConfiguration

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

Through ConfigurationSource

public class ConfigurationSource :
    IConfigurationSource
{
    public T GetConfiguration<T>() where T : class, new()
    {
        if (typeof(T) == typeof(TransportConfig))
        {
            var config = new TransportConfig
            {
                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;
    }
}
busConfiguration.CustomConfigurationSource(new ConfigurationSource());

Disabling

Using app.config

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

Through IProvideConfiguration

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

Through ConfigurationSource

public class DisableConfigurationSource :
    IConfigurationSource
{
    public T GetConfiguration<T>() where T : class, new()
    {
        if (typeof(T) == typeof(TransportConfig))
        {
            var config = new TransportConfig
            {
                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;
    }
}
busConfiguration.CustomConfigurationSource(new DisableConfigurationSource());

Samples


Last modified