Ejemplo n.º 1
0
        async Task IFilter <ClientContext> .Send(ClientContext context, IPipe <ClientContext> next)
        {
            if (context.IsClosedOrClosing)
            {
                return;
            }

            var receiver = CreateMessageReceiver(context, _messageReceiver);

            await receiver.Start().ConfigureAwait(false);

            await receiver.Ready.ConfigureAwait(false);

            _context.AddConsumeAgent(receiver);

            await _transportObserver.Ready(new ReceiveTransportReadyEvent(context.InputAddress)).ConfigureAwait(false);

            try
            {
                await receiver.Completed.ConfigureAwait(false);
            }
            finally
            {
                var metrics = receiver.GetDeliveryMetrics();

                await _transportObserver.Completed(new ReceiveTransportCompletedEvent(context.InputAddress, metrics)).ConfigureAwait(false);

                LogContext.Debug?.Log("Consumer completed {InputAddress}: {DeliveryCount} received, {ConcurrentDeliveryCount} concurrent", context.InputAddress,
                                      metrics.DeliveryCount, metrics.ConcurrentDeliveryCount);
            }

            await next.Send(context).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task Send(OwinHostContext context, IPipe <OwinHostContext> next)
        {
            var inputAddress = context.HostSettings.GetInputAddress();

            using (var scope = _supervisor.CreateScope($"{TypeMetadataCache<HttpConsumerFilter>.ShortName} - {inputAddress}", () => TaskUtil.Completed))
            {
                var controller = new HttpConsumerAction(_receiveObserver, _hostSettings, _receiveSettings, _receivePipe, scope, _sendPipe);

                context.RegisterEndpointHandler(_receiveSettings.PathMatch, controller);

                await scope.Ready.ConfigureAwait(false);

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

                scope.SetReady();

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

                    if (_log.IsDebugEnabled)
                    {
                        _log.DebugFormat("Consumer {0} received, {1} concurrent", metrics.DeliveryCount, metrics.ConcurrentDeliveryCount);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        async Task IFilter <ClientContext> .Send(ClientContext context, IPipe <ClientContext> next)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Creating message receiver for {0}", context.InputAddress);
            }

            var receiver = CreateMessageReceiver(context, _messageReceiver);

            await receiver.Start().ConfigureAwait(false);

            await receiver.Ready.ConfigureAwait(false);

            Add(receiver);

            await _transportObserver.Ready(new ReceiveTransportReadyEvent(context.InputAddress)).ConfigureAwait(false);

            try
            {
                await receiver.Completed.ConfigureAwait(false);
            }
            finally
            {
                var metrics = receiver.GetDeliveryMetrics();

                await _transportObserver.Completed(new ReceiveTransportCompletedEvent(context.InputAddress, metrics)).ConfigureAwait(false);

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

            await next.Send(context).ConfigureAwait(false);
        }
Ejemplo n.º 4
0
        public async Task Send(HttpHostContext context, IPipe <HttpHostContext> next)
        {
            var inputAddress = context.HostSettings.GetInputAddress();

            var consumer = new HttpConsumer(_receiveObserver, _hostSettings, _receivePipe, _context);

            context.RegisterEndpointHandler(_receiveSettings.PathMatch, consumer);

            await consumer.Ready.ConfigureAwait(false);

            Add(consumer);

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

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

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Consumer {0} received, {1} concurrent", metrics.DeliveryCount, metrics.ConcurrentDeliveryCount);
                }
            }
        }
Ejemplo n.º 5
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 queueUrl = await context.GetQueue(receiveSettings.EntityName).ConfigureAwait(false);

            var consumer = new AmazonSqsBasicConsumer(context, queueUrl, inputAddress, _receivePipe, _receiveObserver, _context, _deadLetterTransport, _errorTransport);

            await context.BasicConsume(queueUrl, receiveSettings, 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
            {
                DeliveryMetrics metrics = consumer;
                await _transportObserver.Completed(new ReceiveTransportCompletedEvent(inputAddress, metrics)).ConfigureAwait(false);

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Consumer completed: {0} received, {0} concurrent", metrics.DeliveryCount, metrics.ConcurrentDeliveryCount);
                }
            }
        }
Ejemplo n.º 6
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);
                    }
                }
            }
        }
Ejemplo n.º 7
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, receiveSettings.ConsumeArguments, 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);
                }
            }
        }
Ejemplo n.º 8
0
        public async Task Send(T context, IPipe <T> next)
        {
            await _transportObserver.Ready(new ReceiveTransportReadyEvent(_inputAddress)).ConfigureAwait(false);

            SetReady();

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

            SetCompleted(TaskUtil.Completed);
        }
Ejemplo n.º 9
0
 Task IReceiveTransportObserver.Ready(ReceiveTransportReady ready)
 {
     return(_receiveTransportObserver.Ready(ready));
 }
Ejemplo n.º 10
0
 public static Task NotifyReady(this IReceiveTransportObserver observer, Uri inputAddress)
 {
     return(observer.Ready(new ReceiveTransportReadyEvent(inputAddress)));
 }