Receives messages from RabbitMQ, pushing them to the InboundPipe of the service endpoint.
Inheritance: IBasicConsumer, RabbitMqDeliveryMetrics
Exemple #1
0
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

            var inputAddress = receiveSettings.GetInputAddress(context.ConnectionContext.HostAddress);

            var consumer = new RabbitMqBasicConsumer(context, inputAddress, _receiveEndpointContext);

            await context.BasicConsume(receiveSettings.QueueName, false, _receiveEndpointContext.ExclusiveConsumer, receiveSettings.ConsumeArguments, consumer)
            .ConfigureAwait(false);

            await consumer.Ready.ConfigureAwait(false);

            Add(consumer);

            await _receiveEndpointContext.TransportObservers.Ready(new ReceiveTransportReadyEvent(inputAddress)).ConfigureAwait(false);

            try
            {
                await consumer.Completed.ConfigureAwait(false);
            }
            finally
            {
                RabbitMqDeliveryMetrics metrics = consumer;
                await _receiveEndpointContext.TransportObservers.Completed(new ReceiveTransportCompletedEvent(inputAddress, metrics)).ConfigureAwait(false);

                LogContext.Debug?.Log("Consumer completed {ConsumerTag}: {DeliveryCount} received, {ConcurrentDeliveryCount} concurrent", metrics.ConsumerTag,
                                      metrics.DeliveryCount, metrics.ConcurrentDeliveryCount);
            }
        }
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

            var inputAddress = context.ConnectionContext.HostSettings.GetInputAddress(receiveSettings);

            using (var scope = _taskSupervisor.CreateScope())
            {
                var consumer = new RabbitMqBasicConsumer(context, inputAddress, _receivePipe, _receiveObserver, scope);

                await context.BasicConsume(receiveSettings.QueueName, false, consumer).ConfigureAwait(false);

                await scope.Ready.ConfigureAwait(false);

                await _endpointObserver.Ready(new Ready(inputAddress)).ConfigureAwait(false);

                scope.SetReady();

                try
                {
                    await scope.Completed.ConfigureAwait(false);
                }
                finally
                {
                    RabbitMqConsumerMetrics metrics = consumer;
                    await _endpointObserver.Completed(new Completed(inputAddress, metrics)).ConfigureAwait(false);

                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Consumer {0}: {1} received, {2} concurrent", metrics.ConsumerTag, metrics.DeliveryCount,
                                         metrics.ConcurrentDeliveryCount);
                    }
                }
            }
        }
Exemple #3
0
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

            var inputAddress = receiveSettings.GetInputAddress(context.ConnectionContext.HostSettings.HostAddress);

            var consumer = new RabbitMqBasicConsumer(context, inputAddress, _receivePipe, _receiveObserver, _receiveEndpointContext, _deadLetterTransport, _errorTransport);

            await context.BasicConsume(receiveSettings.QueueName, false, consumer).ConfigureAwait(false);

            await consumer.Ready.ConfigureAwait(false);

            Add(consumer);

            await _transportObserver.Ready(new ReceiveTransportReadyEvent(inputAddress)).ConfigureAwait(false);

            try
            {
                await consumer.Completed.ConfigureAwait(false);
            }
            finally
            {
                RabbitMqDeliveryMetrics metrics = consumer;
                await _transportObserver.Completed(new ReceiveTransportCompletedEvent(inputAddress, metrics)).ConfigureAwait(false);

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Consumer completed {0}: {1} received, {2} concurrent", metrics.ConsumerTag, metrics.DeliveryCount,
                                     metrics.ConcurrentDeliveryCount);
                }
            }
        }
Exemple #4
0
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

            var inputAddress = receiveSettings.GetInputAddress(context.ConnectionContext.HostSettings.HostAddress);

            using (var scope = _supervisor.CreateScope($"{TypeMetadataCache<RabbitMqConsumerFilter>.ShortName} - {inputAddress}", () => TaskUtil.Completed))
            {
                var consumer = new RabbitMqBasicConsumer(context, inputAddress, _receivePipe, _receiveObserver, scope, _sendEndpointProvider, _publishEndpointProvider);

                await context.BasicConsume(receiveSettings.QueueName, false, consumer).ConfigureAwait(false);

                await scope.Ready.ConfigureAwait(false);

                await _transportObserver.Ready(new ReceiveTransportReadyEvent(inputAddress)).ConfigureAwait(false);

                scope.SetReady();

                try
                {
                    await scope.Completed.ConfigureAwait(false);
                }
                finally
                {
                    RabbitMqDeliveryMetrics metrics = consumer;
                    await _transportObserver.Completed(new ReceiveTransportCompletedEvent(inputAddress, metrics)).ConfigureAwait(false);

                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Consumer {0}: {1} received, {2} concurrent", metrics.ConsumerTag, metrics.DeliveryCount,
                                         metrics.ConcurrentDeliveryCount);
                    }
                }
            }
        }
        async Task IFilter <ModelContext> .Send(ModelContext context, IPipe <ModelContext> next)
        {
            var receiveSettings = context.GetPayload <ReceiveSettings>();

            Uri inputAddress = context.ConnectionContext.HostSettings.GetInputAddress(receiveSettings);

            using (var consumer = new RabbitMqBasicConsumer(context, inputAddress, _receivePipe, _receiveObserver, context.CancellationToken))
            {
                await context.BasicConsume(receiveSettings.QueueName, false, consumer);

                await _endpointObserver.Ready(new Ready(inputAddress));

                RabbitMqConsumerMetrics metrics = await consumer.CompleteTask;

                await _endpointObserver.Completed(new Completed(inputAddress, metrics));

                if (_log.IsDebugEnabled)
                {
                    _log.InfoFormat("Consumer {0}: {1} received, {2} concurrent", metrics.ConsumerTag, metrics.DeliveryCount,
                                    metrics.ConcurrentDeliveryCount);
                }
            }
        }