Ejemplo n.º 1
0
        async Task HandleMessage(Message message)
        {
            if (IsStopping)
            {
                return;
            }



            var redelivered = message.Attributes.TryGetInt("ApproximateReceiveCount", out var receiveCount) && receiveCount > 1;

            var context = new AmazonSqsReceiveContext(message, redelivered, _context, _client, _receiveSettings, _client.ConnectionContext);

            try
            {
                await _dispatcher.Dispatch(context, context).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                context.LogTransportFaulted(exception);
            }
            finally
            {
                context.Dispose();
            }
        }
Ejemplo n.º 2
0
        public async Task HandleMessage(Message message)
        {
            if (IsStopping)
            {
                await WaitAndAbandonMessage().ConfigureAwait(false);

                return;
            }

            var redelivered = message.Attributes.TryGetValue("ApproximateReceiveCount", out var receiveCountStr) &&
                              int.TryParse(receiveCountStr, out var receiveCount) && receiveCount > 1;

            var context = new AmazonSqsReceiveContext(message, redelivered, _context, _client, _receiveSettings, _client.ConnectionContext);

            if (!_pending.TryAdd(message.MessageId, context))
            {
                LogContext.Error?.Log("Duplicate message: {MessageId}", message.MessageId);
            }

            try
            {
                await _dispatcher.Dispatch(context, context).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                context.LogTransportFaulted(exception);
            }
            finally
            {
                _pending.TryRemove(message.MessageId, out _);

                context.Dispose();
            }
        }