public override async Task ReceiveMessage()
{
Message message = null;
try
{
using (var msmqTransaction = new MessageQueueTransaction())
{
msmqTransaction.Begin();
if (!TryReceive(msmqTransaction, out message))
{
return;
}
Dictionary<string, string> headers;
if (!TryExtractHeaders(message, out headers))
{
MovePoisonMessageToErrorQueue(message, msmqTransaction);
msmqTransaction.Commit();
return;
}
var shouldCommit = await ProcessMessage(msmqTransaction, message, headers).ConfigureAwait(false);
if (shouldCommit)
{
msmqTransaction.Commit();
}
else
{
msmqTransaction.Abort();
}
}
}
// We'll only get here if Commit/Abort/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);
}
}