BEagle1984 / silverback

Silverback is a simple but feature-rich message bus for .NET core (it currently supports Kafka, RabbitMQ and MQTT).
https://silverback-messaging.net
MIT License
257 stars 37 forks source link

ErrorPolicy Exclude #207

Closed marcospiresvortigo closed 1 year ago

marcospiresvortigo commented 1 year ago

Hi, I would like some guidance regarding a configuration, my intention with the code below is that the retry policy does not apply to the "BaseExcludeRetryException" and if this exception occurs, it will publish in a topic that I defined below, my configuration is correct ? Because even with exclude the retry policy is being applied.

_ = policy.Retry(consumerConfiguration.RetryCount ?? retryCount,
                             TimeSpan.FromSeconds(consumerConfiguration.SecondsBetweenRetry ?? secondsBetweenRetry),errorPolicy =>
                             {
                                 errorPolicy.Exclude(typeof(BaseExcludeRetryException));
                             })
                      .ThenMoveToKafkaTopic(x => x.ProduceTo(GetDeadLetterName(consumerConfiguration.Origin, deadLetterSuffix)))
                      .ThenSkip();

            _ = policy.MoveToKafkaTopic(x => x.ProduceTo(GetExcludeRetryExceptionName(consumerConfiguration.Origin, excludeExceptionSuffix)),errorPolicy =>
            {
                errorPolicy.ApplyWhen((_, exception) => exception.GetType() == typeof(BaseExcludeRetryException));
                errorPolicy.Publish((_, exception) =>
                {
                    if (exception.GetType() == typeof(BaseExcludeRetryException))
                    {
                        return ((BaseExcludeRetryException)exception).Event;
                    }
                    return null;
                });
            });