Reputation: 11
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
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