Exemple #1
0
        void HandleMessage(IMessage message)
        {
            _executor.PushWithWait(async() =>
            {
                LogContext.Current = _context.LogContext;

                if (IsStopping)
                {
                    await WaitAndAbandonMessage().ConfigureAwait(false);
                    return;
                }

                var context = new ActiveMqReceiveContext(message, _context, _receiveSettings, _session, _session.ConnectionContext);

                try
                {
                    await _dispatcher.Dispatch(context, context).ConfigureAwait(false);
                }
                catch (Exception exception)
                {
                    context.LogTransportFaulted(exception);
                }
                finally
                {
                    context.Dispose();
                }
            }, Stopping);
        }
        async void HandleMessage(IMessage message)
        {
            LogContext.Current = _context.LogContext;

            if (IsStopping)
            {
                await WaitAndAbandonMessage(message).ConfigureAwait(false);

                return;
            }

            var delivery = _tracker.BeginDelivery();

            var context = new ActiveMqReceiveContext(_inputAddress, message, _context, _receiveSettings, _session, _session.ConnectionContext);

            var activity = LogContext.IfEnabled(OperationName.Transport.Receive)?.StartActivity();

            activity.AddReceiveContextHeaders(context);

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

                if (_context.ReceiveObservers.Count > 0)
                {
                    await _context.ReceiveObservers.PreReceive(context).ConfigureAwait(false);
                }

                await _context.ReceivePipe.Send(context).ConfigureAwait(false);

                await context.ReceiveCompleted.ConfigureAwait(false);

                message.Acknowledge();

                if (_context.ReceiveObservers.Count > 0)
                {
                    await _context.ReceiveObservers.PostReceive(context).ConfigureAwait(false);
                }
            }
            catch (Exception ex)
            {
                if (_context.ReceiveObservers.Count > 0)
                {
                    await _context.ReceiveObservers.ReceiveFault(context, ex).ConfigureAwait(false);
                }
            }
            finally
            {
                activity?.Stop();

                delivery.Dispose();

                _pending.TryRemove(message.NMSMessageId, out _);

                context.Dispose();
            }
        }
Exemple #3
0
        void HandleMessage(IMessage message)
        {
            Task.Run(async() =>
            {
                LogContext.Current = _context.LogContext;

                if (IsStopping)
                {
                    await WaitAndAbandonMessage().ConfigureAwait(false);
                    return;
                }

                var context = new ActiveMqReceiveContext(message, _context, _receiveSettings, _session, _session.ConnectionContext);
                if (!_pending.TryAdd(message.NMSMessageId, context))
                {
                    LogContext.Warning?.Log("Duplicate message: {MessageId}", message.NMSMessageId);
                }

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

                    context.Dispose();
                }
            });
        }
Exemple #4
0
        async void HandleMessage(IMessage message)
        {
            if (IsStopping)
            {
                await WaitAndAbandonMessage(message).ConfigureAwait(false);

                return;
            }

            using (var delivery = _tracker.BeginDelivery())
            {
                var context = new ActiveMqReceiveContext(_inputAddress, message, _context);

                context.GetOrAddPayload(() => _receiveSettings);
                context.GetOrAddPayload(() => _session);
                context.GetOrAddPayload(() => _session.ConnectionContext);

                try
                {
                    if (!_pending.TryAdd(message.NMSMessageId, context))
                    {
                        if (_log.IsErrorEnabled)
                        {
                            _log.ErrorFormat("Duplicate BasicDeliver: {0}", message.NMSMessageId);
                        }
                    }

                    await _context.ReceiveObservers.PreReceive(context).ConfigureAwait(false);

                    await _context.ReceivePipe.Send(context).ConfigureAwait(false);

                    await context.ReceiveCompleted.ConfigureAwait(false);

                    message.Acknowledge();

                    await _context.ReceiveObservers.PostReceive(context).ConfigureAwait(false);
                }
                catch (Exception ex)
                {
                    await _context.ReceiveObservers.ReceiveFault(context, ex).ConfigureAwait(false);

                    try
                    {
                        //                        _session.BasicNack(deliveryTag, false, true);
                    }
                    catch (Exception ackEx)
                    {
                        if (_log.IsErrorEnabled)
                        {
                            _log.ErrorFormat("An error occurred trying to NACK a message with delivery tag {0}: {1}", message.NMSMessageId, ackEx.ToString());
                        }
                    }
                }
                finally
                {
                    _pending.TryRemove(message.NMSMessageId, out _);

                    context.Dispose();
                }
            }
        }