pardahlman / RawRabbit

A modern .NET framework for communication over RabbitMq
MIT License
746 stars 144 forks source link

RetryLatter Functionality #356

Closed ulmermark closed 5 years ago

ulmermark commented 6 years ago

I am trying to use the retry later functionality and DO NOT ever see the message being retried at a later point in time.

Currently using ASPNETCORE 2.0.3

I have added <PackageReference Include="RawRabbit.Enrichers.RetryLater" Version="2.0.0-rc5" /> to the csproj file

The IBusClient is injected into the IOC container using the following

            var section = config.GetSection (OPTIONS_PREFIX);

            RawRabbitOptions options  = section != null && section.GetChildren().Any() ? new RawRabbitOptions (){
                ClientConfiguration = (section.Get<RawRabbitConfiguration> ())
            } : new RawRabbitOptions();

            options.Plugins = p => p.UseRetryLater();

            return services.AddRawRabbit (options);

I publish the message and the message handler run as expected but when the exception is thrown ( random divide by 0), I do not see the message ever being "reprocessed"

        private async Task<Acknowledgement> MessageEventMessageHandlerAsync (MessageEvent arg) {
            try {
                var x = 1 / (DateTime.Now.Second % 2);
                logger.LogInformation ("MessageEventMessageHandlerAsync - calling Ack()");
                return new Ack ();
            } catch (Exception e) {
                logger.LogInformation ("MessageEventMessageHandlerAsync - calling Retry()");
                return Retry.In (TimeSpan.FromSeconds (5));
            }

Is there enything else that must be done to get the "Retry" enricher to work?

sayfulloev commented 6 years ago

I believe you might be missing Message context in this case. following code is similar to what we have in our Retry strategy of .SubscribeAsync() method of IBusClient

client.SubSubscribeAsync<T, RetryMessageContext> ( 
    async (msg, context) => 
{
    // Handle stuff here and return Retry.In if things go wrong 
},    
ctx => ctx.UseMessageContext(c => new RetryMessageContext { 
    GlobalRequestId = Guid.NewGuid(), 
    RetryInfo = c.GetRetryInformation() }));

RetryMessageContext - is simple class that implements IMessageContext