Nservice MSMQ transport retry mechanism not working

retries
msmq
nservicebus

(Prasanth Joseph) #1

Below is the code i am using to create message

            var NserviceBusTestendpointConfiguration = new EndpointConfiguration(endpointName: "NserviceBusTest");
            NserviceBusTestendpointConfiguration.SendFailedMessagesTo("NserviceBusTestErrors");
            NserviceBusTestendpointConfiguration.UseSerialization<XmlSerializer>();
            NserviceBusTestendpointConfiguration.EnableInstallers();
            NserviceBusTestendpointConfiguration.UseTransport<MsmqTransport>();
            NserviceBusTestendpointConfiguration.UsePersistence<MsmqPersistence>();
            NserviceBusTestendpointConfiguration.DisableFeature<TimeoutManager>();


            NserviceBusTestendpointInstance = await Endpoint.Start(NserviceBusTestendpointConfiguration).ConfigureAwait(false);


            try
            {
  		NServiceBusInfo gInfo = new NServiceBusInfo(Guid.NewGuid());
            //gInfo.JSonValue = strFitBitData;
            gInfo.RequestDateTime = DateTime.Now;
            await endpointInstance.SendLocal(gInfo)
                 .ConfigureAwait(false); // Send the object to process

            }
            catch (Exception ex)
            {
                ExceptionlessClient.Default.CreateException(ex);
            }
            finally
            {
                await NserviceBusTestendpointInstance.Stop().ConfigureAwait(false);
            }

and below is the code for processing the message

    class ProcessMessage : IHandleMessages<NServiceBusInfo>
    {
        static Random random = new Random();
        public Task Handle(NServiceBusInfo message, IMessageHandlerContext context)
        {
            

                throw new Exception("Oops");
            return Task.FromResult(0);
           
        }
    }

I am explicitly throwing exception here but the retry mechanism is not working, the message stays in the same queue ? Can someone throw light if there is anything wrong with the configuration.


(Ramon Smits) #2

Your endpoints starts and then stops immediately.

I suggest you add a Console.ReadKey() to actually see the message processing and retries.

Based on the code I see I would expect your message eventually be send to NserviceBusTestErrors. Can you share any log data if you do not see this behavior.


(Mauro Servienti) #3

As @ramonsmits pointed out your endpoint is stopping too early, take a look at the following sample that works as expected:

class Program
{
    static async Task Main(string[] args)
    {
        var endpointConfig = new EndpointConfiguration(endpointName: "NserviceBusTest");
        endpointConfig.SendFailedMessagesTo("error");
        endpointConfig.UseSerialization<XmlSerializer>();
        endpointConfig.EnableInstallers();
        endpointConfig.UseTransport<MsmqTransport>();
        endpointConfig.UsePersistence<MsmqPersistence>();
        endpointConfig.DisableFeature<TimeoutManager>();


        var endpointInstance = await Endpoint.Start(endpointConfig).ConfigureAwait(false);


        SampleMessage gInfo = new SampleMessage
        {
            MyProperty = Guid.NewGuid().ToString()
        };

        gInfo.RequestDateTime = DateTime.Now;
        await endpointInstance.SendLocal(gInfo)
                .ConfigureAwait(false);

        Console.Read();


        await endpointInstance.Stop().ConfigureAwait(false);
    }
}

And the message handler:

class ProcessMessage : IHandleMessages<SampleMessage>
{
    public Task Handle(SampleMessage message, IMessageHandlerContext context)
    {
        throw new Exception("Oops");
    }
}

Another important thing to notice is that since you are explicitly disabling the TimeoutManager the only retry engine that will kick in is the immediate retries, then messages will be immediately moved to the configured error queue. Delayed retries in your configuration are disabled.