I have several WebJobs with ServiceBus triggers, and I have a custom MessageProcessor to do some processing after the message has finished processing.
I'd like to be able to do something different (specifically, log an Error instead of a Warning) if the message is on its last retry, i.e. it's just about to be sent to the deadletter queue. The BrokeredMessage sent into the CompleteProcessingMessageAsync function has the DeliveryCount, but I can't see a way to get back to the original queue to find the MaxDeliveryCount. Any ideas? Different queues have different MaxDeliveryCounts, so setting a constant isn't really an option. The only other thing I can think of is to create a separate job for each queue's dead letter queue, but I'd like to be able to do it at the WebJob level rather than for each individual job.
public class CustomMessageProcessor : MessageProcessor
{
public CustomMessageProcessor(OnMessageOptions messageOptions) : base(messageOptions)
{
}
public override async Task CompleteProcessingMessageAsync(BrokeredMessage message, FunctionResult result, CancellationToken cancellationToken)
{
if (result.Succeeded)
{
if (!MessageOptions.AutoComplete)
{
cancellationToken.ThrowIfCancellationRequested();
await message.CompleteAsync();
}
}
else
{
cancellationToken.ThrowIfCancellationRequested();
//some other processing
//If message.DeliveryCount < maxDeliveryCount
// log warning
//else
// log error
await message.AbandonAsync();
}
}
}