Andrea Perazzolo
Andrea Perazzolo

Reputation: 11

NServiceBus Message Handlers and Retries

I have the following problem with NServiceBus. After an exception in an h NServicebus I Log to Application Insights. If the error is not transient the log is repeated every retry till the message goes in the error queue.

There is a way in the handler to recognize if I am in the first iteration or in one of the retries without implementing custom code?

I have seen that there is a global Notification System, But I will need to have it at Handler level.

Upvotes: 1

Views: 1120

Answers (1)

Loe Lobo
Loe Lobo

Reputation: 46

You can check the message headers.

public Task Handle(MyMessage message, IMessageHandlerContext context) { var numberImmediateRetries = context.MessageHeaders[NServiceBus.Headers.ImmediateRetries]; var numberDelayedRetries = context.MessageHeaders[NServiceBus.Headers.DelayedRetries]; }

Upvotes: 1

Related Questions