Inheritance: BaseReceiveContext
        public async Task Consume(InMemoryTransportMessage message, CancellationToken cancellationToken)
        {
            await Ready.ConfigureAwait(false);

            if (IsStopped)
            {
                return;
            }

            LogContext.Current = _context.LogContext;

            var context = new InMemoryReceiveContext(message, _context);

            try
            {
                await _dispatcher.Dispatch(context).ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                message.DeliveryCount++;
                context.LogTransportFaulted(exception);
            }
            finally
            {
                context.Dispose();
            }
        }
        public async Task Consume(InMemoryTransportMessage message, CancellationToken cancellationToken)
        {
            await Ready.ConfigureAwait(false);

            if (IsStopped)
            {
                return;
            }

            var context = new InMemoryReceiveContext(_inputAddress, message, _receiveEndpointContext);

            using (_tracker.BeginDelivery())
            {
                try
                {
                    await _receiveEndpointContext.ReceiveObservers.PreReceive(context).ConfigureAwait(false);

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

                    await context.ReceiveCompleted.ConfigureAwait(false);

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

                    message.DeliveryCount++;
                }
                finally
                {
                    context.Dispose();
                }
            }
        }
Example #3
0
        public async Task Consume(InMemoryTransportMessage message, CancellationToken cancellationToken)
        {
            await Ready.ConfigureAwait(false);

            if (IsStopped)
            {
                return;
            }

            LogContext.Current = _context.LogContext;

            var context  = new InMemoryReceiveContext(_inputAddress, message, _context);
            var delivery = _tracker.BeginDelivery();

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

            activity.AddReceiveContextHeaders(context);

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

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

                await context.ReceiveCompleted.ConfigureAwait(false);

                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);
                }

                message.DeliveryCount++;
            }
            finally
            {
                activity?.Stop();

                delivery.Dispose();

                context.Dispose();
            }
        }
        async Task DispatchMessage(InMemoryTransportMessage message)
        {
            await _supervisor.Ready.ConfigureAwait(false);

            if (_supervisor.StopToken.IsCancellationRequested)
            {
                return;
            }

            if (_receivePipe == null)
            {
                throw new ArgumentException("ReceivePipe not configured");
            }

            var context = new InMemoryReceiveContext(_inputAddress, message, _receiveObservable);

            Interlocked.Increment(ref _deliveryCount);

            var current = Interlocked.Increment(ref _currentPendingDeliveryCount);

            while (current > _maxPendingDeliveryCount)
            {
                Interlocked.CompareExchange(ref _maxPendingDeliveryCount, current, _maxPendingDeliveryCount);
            }

            try
            {
                await _receiveObservable.PreReceive(context).ConfigureAwait(false);

                await _receivePipe.Send(context).ConfigureAwait(false);

                await context.CompleteTask.ConfigureAwait(false);

                await _receiveObservable.PostReceive(context).ConfigureAwait(false);

                _inputAddress.LogReceived(message.MessageId.ToString("N"), message.MessageType);
            }
            catch (Exception ex)
            {
                _log.Error($"RCV FAULT: {message.MessageId}", ex);

                await _receiveObservable.ReceiveFault(context, ex).ConfigureAwait(false);

                message.DeliveryCount++;
            }
            finally
            {
                Interlocked.Decrement(ref _currentPendingDeliveryCount);
            }
        }
        public async Task Consume(InMemoryTransportMessage message, CancellationToken cancellationToken)
        {
            await Ready.ConfigureAwait(false);

            if (IsStopped)
            {
                return;
            }

            if (_receivePipe == null)
            {
                throw new ArgumentException("ReceivePipe not configured");
            }

            var context = new InMemoryReceiveContext(_inputAddress, message, _receiveObservable, _topology);

            context.GetOrAddPayload(() => _errorTransport);
            context.GetOrAddPayload(() => _deadLetterTransport);

            using (_tracker.BeginDelivery())
            {
                try
                {
                    await _receiveObservable.PreReceive(context).ConfigureAwait(false);

                    await _receivePipe.Send(context).ConfigureAwait(false);

                    await context.CompleteTask.ConfigureAwait(false);

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

                    message.DeliveryCount++;
                }
                finally
                {
                    context.Dispose();
                }
            }
        }
Example #6
0
        async Task DispatchMessage(InMemoryTransportMessage message)
        {
            await _supervisor.Ready.ConfigureAwait(false);

            if (_supervisor.StoppedToken.IsCancellationRequested)
            {
                return;
            }

            if (_receivePipe == null)
            {
                throw new ArgumentException("ReceivePipe not configured");
            }

            var context = new InMemoryReceiveContext(_inputAddress, message, _receiveObservable, _sendEndpointProvider, _publishEndpointProvider);

            using (_tracker.BeginDelivery())
            {
                try
                {
                    await _receiveObservable.PreReceive(context).ConfigureAwait(false);

                    await _receivePipe.Send(context).ConfigureAwait(false);

                    await context.CompleteTask.ConfigureAwait(false);

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

                    message.DeliveryCount++;
                }
                finally
                {
                    Interlocked.Decrement(ref _queueDepth);

                    context.Dispose();
                }
            }
        }