I have several WebJobs with ServiceBus triggers, and I have a custom MessageProcessor to do some processing after the message has finished processing.
I would like to be able to do something else (in particular, register an error instead of a warning) if the message is in his last attempt, i.e. it will simply be sent to the queue with an error. BrokeredMessage sent to the CompleteProcessingMessageAsync function has a DeliveryCount, but I see no way to return to the original queue to find MaxDeliveryCount. Any ideas? Different queues have different MaxDeliveryCounts, so setting a constant is not really an option. The only thing I can think of is to create a separate task for each queue of the queue queue, but I would like to be able to do it at the WebJob level, and not for each separate task.
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();
await message.AbandonAsync();
}
}
}