Custom exception based policy in NSB5

(Ismael Hamed) #1

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.

(Tim Bussmann) #2

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:

V6 has a new custom retry policy API which allows you easier access to the configured settings. See for more information.

(Ismael Hamed) #3

Thanks Tim, for pointing me in the right direction.