Custom exception based policy in NSB5

Is there a way to retrieve the Second Level Retries configuration from inside a Custom Retry Policy? i.e, given the example from the documentation:

TimeSpan MyCustomRetryPolicy(TransportMessage transportMessage)
{
    if (ExceptionType(transportMessage) == typeof(MyBusinessException).FullName)
    {
        // custom retry policy
        ...
    }

    ...

    // else use default retry policy
    return TimeSpan.FromSeconds(5);
}

I’d like to use the configuration of SecondLevelRetriesConfig (or default if not set) instead of hardcoding a TimeSpan of 5 secs.

while not directly support in v5, you should be able to work around by using something like this:

        configuration.SecondLevelRetries().CustomRetryPolicy(tm => MyRetryPolicy(tm, configuration.GetSettings()));

        TimeSpan MyRetryPolicy(TransportMessage tm, SettingsHolder settings)
        {
            var slrConfig = settings.GetConfigSection<SecondLevelRetriesConfig>();
            return slrConfig.TimeIncrease;
        }

To be tested though :wink: Also keep in mind to ensure that your custom retry policy should make sure that messages aren’t retried infinitely. See the custom retry docs for an example how to do that here: Configure delayed retries • NServiceBus • Particular Docs

V6 has a new custom retry policy API which allows you easier access to the configured settings. See Custom Recoverability Policy • NServiceBus • Particular Docs for more information.

Thanks Tim, for pointing me in the right direction.