public override async Task ReceiveMessage()
{
Message message = null;
try
{
using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew, transactionOptions, TransactionScopeAsyncFlowOption.Enabled))
{
if (!TryReceive(MessageQueueTransactionType.Automatic, out message))
{
return;
}
Dictionary<string, string> headers;
if (!TryExtractHeaders(message, out headers))
{
MovePoisonMessageToErrorQueue(message, MessageQueueTransactionType.Automatic);
scope.Complete();
return;
}
var shouldCommit = await ProcessMessage(message, headers).ConfigureAwait(false);
if (!shouldCommit)
{
return;
}
scope.Complete();
}
}
// We'll only get here if Complete/Dispose throws which should be rare.
// Note: If that happens the attempts counter will be inconsistent since the message might be picked up again before we can register the failure in the LRU cache.
catch (Exception exception)
{
if (message == null)
{
throw;
}
failureInfoStorage.RecordFailureInfoForMessage(message.Id, exception);
}
}