Configure immediate retries

Component: NServiceBus | Nuget: NServiceBus (Version: 4.x)
Standard support for version 4.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

Using app.config

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

Through IProvideConfiguration

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

Through ConfigurationSource

Edit
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;
    }
}
Edit
configure.CustomConfigurationSource(new ConfigurationSource());

Disabling

Using app.config

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

Through IProvideConfiguration

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

Through ConfigurationSource

Edit
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;
    }
}
Edit
configure.CustomConfigurationSource(new DisableConfigurationSource());

Samples


Last modified