コード例 #1
0
ファイル: InternalConsumer.cs プロジェクト: the-vk/EasyNetQ
        public void HandleBasicDeliver(
            string consumerTag,
            ulong deliveryTag,
            bool redelivered,
            string exchange,
            string routingKey,
            IBasicProperties properties,
            byte[] body)
        {
            logger.DebugWrite("HandleBasicDeliver on consumer: {0}, deliveryTag: {1}", consumerTag, deliveryTag);

            if (disposed)
            {
                // this message's consumer has stopped, so just return
                logger.InfoWrite("Consumer has stopped running. Consumer '{0}' on queue '{1}'. Ignoring message",
                                 ConsumerTag, queue.Name);
                return;
            }

            if (onMessage == null)
            {
                logger.ErrorWrite("User consumer callback, 'onMessage' has not been set for consumer '{0}'." +
                                  "Please call InternalConsumer.StartConsuming before passing the consumer to basic.consume",
                                  ConsumerTag);
                return;
            }

            var messageReceivedInfo = new MessageReceivedInfo(consumerTag, deliveryTag, redelivered, exchange, routingKey, queue.Name);
            var messsageProperties  = new MessageProperties(properties);
            var context             = new ConsumerExecutionContext(onMessage, messageReceivedInfo, messsageProperties, body, this);

            consumerDispatcher.QueueAction(() => handlerRunner.InvokeUserMessageHandler(context));
        }
コード例 #2
0
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }
            disposed = true;



            var model = Model;

            if (model != null)
            {
                // Queued because we may be on the RabbitMQ.Client dispatch thread.
                consumerDispatcher.QueueAction(() =>
                {
                    Model.Dispose();
                    foreach (var c in basicConsumers)
                    {
                        c.Dispose();
                    }
                });
            }
        }
コード例 #3
0
        public void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, byte[] body)
        {
            logger.DebugFormat("Message delivered to consumer {consumerTag} with deliveryTag {deliveryTag}", consumerTag, deliveryTag);

            if (disposed)
            {
                // this message's consumer has stopped, so just return
                logger.InfoFormat(
                    "Consumer with consumerTag {consumerTag} on queue {queue} has stopped running. Ignoring message",
                    ConsumerTag,
                    Queue.Name
                    );

                return;
            }

            var messageReceivedInfo = new MessageReceivedInfo(consumerTag, deliveryTag, redelivered, exchange, routingKey, Queue.Name);
            var messsageProperties  = new MessageProperties(properties);
            var context             = new ConsumerExecutionContext(OnMessage, messageReceivedInfo, messsageProperties, body, this);

            consumerDispatcher.QueueAction(() =>
            {
                eventBus.Publish(new DeliveredMessageEvent(messageReceivedInfo, messsageProperties, body));
                handlerRunner.InvokeUserMessageHandler(context);
            });
        }
コード例 #4
0
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }
            disposed = true;

            var model = Model;

            if (model != null)
            {
                // Queued because we may be on the RabbitMQ.Client dispatch thread.
                var disposedEvent = new AutoResetEvent(false);
                consumerDispatcher.QueueAction(() =>
                {
                    foreach (var c in basicConsumers)
                    {
                        c.Dispose();
                    }
                    model.Dispose();
                    disposedEvent.Set();
                });
                disposedEvent.WaitOne();
            }
        }
コード例 #5
0
ファイル: InternalConsumer.cs プロジェクト: y2ket/EasyNetQ
        /// <inheritdoc />
        public void HandleBasicDeliver(
            string consumerTag,
            ulong deliveryTag,
            bool redelivered,
            string exchange,
            string routingKey,
            IBasicProperties properties,
            ReadOnlyMemory <byte> body
            )
        {
            if (logger.IsDebugEnabled())
            {
                logger.DebugFormat("Message delivered to consumer {consumerTag} with deliveryTag {deliveryTag}", consumerTag, deliveryTag);
            }

            if (disposed)
            {
                // this message's consumer has stopped, so just return
                logger.InfoFormat(
                    "Consumer with consumerTag {consumerTag} on queue {queue} has stopped running. Ignoring message",
                    ConsumerTag,
                    Queue.Name
                    );

                return;
            }

            var bodyBytes           = body.ToArray();
            var messageReceivedInfo = new MessageReceivedInfo(consumerTag, deliveryTag, redelivered, exchange, routingKey, Queue.Name);
            var messageProperties   = new MessageProperties(properties);
            var context             = new ConsumerExecutionContext(OnMessage, messageReceivedInfo, messageProperties, bodyBytes);

            eventBus.Publish(new DeliveredMessageEvent(messageReceivedInfo, messageProperties, bodyBytes));
            handlerRunner.InvokeUserMessageHandlerAsync(context)
            .ContinueWith(async x =>
            {
                var ackStrategy = await x.ConfigureAwait(false);
                consumerDispatcher.QueueAction(() =>
                {
                    var ackResult = ackStrategy(Model, deliveryTag);
                    eventBus.Publish(new AckEvent(messageReceivedInfo, messageProperties, bodyBytes, ackResult));
                });
            },
                          TaskContinuationOptions.ExecuteSynchronously
                          );
        }