Ejemplo n.º 1
0
        private async Task HandleAsync(Message message)
        {
            if (_stopped)
            {
                return;
            }

            var receiptHandle = message.ReceiptHandle;

            Task DeleteMessageAsync(CancellationToken cancellationToken = default(CancellationToken)) =>
            DeleteAsync(receiptHandle, cancellationToken);

            Task RollbackMessageAsync(CancellationToken cancellationToken = default(CancellationToken)) =>
            RollbackAsync(receiptHandle, cancellationToken);

            using var receiverMessage = new SQSReceiverMessage(message, DeleteMessageAsync, RollbackMessageAsync, UnpackSNS);

            try
            {
                await MessageHandler !.OnMessageReceivedAsync(this, receiverMessage).ConfigureAwait(false);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                OnError("Error in MessageHandler.OnMessageReceivedAsync.", ex);
            }
            finally
            {
                if (AutoAcknwoledge && !receiverMessage.Handled)
                {
                    try
                    {
                        await DeleteMessageAsync().ConfigureAwait(false);
                    }
#pragma warning disable CA1031 // Do not catch general exception types
                    catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
                    {
                        OnError("Error in AutoAcknowledge.", ex);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private async Task HandleAsync(Message message)
        {
            if (_stopped)
            {
                return;
            }

            var receiptHandle = message.ReceiptHandle;

            Task DeleteMessageAsync(CancellationToken cancellationToken = default(CancellationToken)) =>
            DeleteAsync(receiptHandle, cancellationToken);

            var receiverMessage = new SQSReceiverMessage(message, DeleteMessageAsync, UnpackSNS);

            try
            {
                await MessageHandler.OnMessageReceivedAsync(this, receiverMessage).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                OnError("Error in MessageHandler.OnMessageReceivedAsync.", ex);
            }
            finally
            {
                if (AutoAcknwoledge && !receiverMessage.Handled)
                {
                    try
                    {
                        await DeleteMessageAsync().ConfigureAwait(false);
                    }
                    catch (Exception ex)
                    {
                        OnError("Error in AutoAcknowledge.", ex);
                    }
                }
            }
        }