Beispiel #1
0
        public When_a_user_handler_is_executed()
        {
            var consumerErrorStrategy = Substitute.For <IConsumerErrorStrategy>();
            var eventBus = new EventBus();

            handlerRunner = new HandlerRunner(consumerErrorStrategy, eventBus);

            Func <byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) =>
                                                                                      Task.Factory.StartNew(() =>
            {
                deliveredBody       = body;
                deliveredProperties = properties;
                deliveredInfo       = info;
            });

            var consumer = Substitute.For <IBasicConsumer>();

            channel = Substitute.For <IModel>();
            consumer.Model.Returns(channel);

            var context = new ConsumerExecutionContext(
                userHandler, messageInfo, messageProperties, messageBody, consumer);

            var autoResetEvent = new AutoResetEvent(false);

            eventBus.Subscribe <AckEvent>(x => autoResetEvent.Set());

            handlerRunner.InvokeUserMessageHandler(context);

            autoResetEvent.WaitOne(1000);
        }
Beispiel #2
0
        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));
        }
        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);
            });
        }
        public void SetUp()
        {
            //var logger = new ConsoleLogger();
            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();
            var consumerErrorStrategy = MockRepository.GenerateStub <IConsumerErrorStrategy>();
            var eventBus = new EventBus();

            handlerRunner = new HandlerRunner(logger, consumerErrorStrategy, eventBus);

            Func <byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) =>
                                                                                      Task.Factory.StartNew(() =>
            {
                deliveredBody       = body;
                deliveredProperties = properties;
                deliveredInfo       = info;
            });

            var consumer = MockRepository.GenerateStub <IBasicConsumer>();

            channel = MockRepository.GenerateStub <IModel>();
            consumer.Stub(x => x.Model).Return(channel).Repeat.Any();

            var context = new ConsumerExecutionContext(
                userHandler, messageInfo, messageProperties, messageBody, consumer);

            var autoResetEvent = new AutoResetEvent(false);

            eventBus.Subscribe <AckEvent>(x => autoResetEvent.Set());

            handlerRunner.InvokeUserMessageHandler(context);

            autoResetEvent.WaitOne(1000);
        }
        public void SetUp()
        {
            //var logger = new ConsoleLogger();
            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();
            var consumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();
            var eventBus = new EventBus();

            handlerRunner = new HandlerRunner(logger, consumerErrorStrategy, eventBus);

            Func<byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) => 
                Task.Factory.StartNew(() =>
                    {
                        deliveredBody = body;
                        deliveredProperties = properties;
                        deliveredInfo = info;
                    });

            var consumer = MockRepository.GenerateStub<IBasicConsumer>();
            channel = MockRepository.GenerateStub<IModel>();
            consumer.Stub(x => x.Model).Return(channel).Repeat.Any();

            var context = new ConsumerExecutionContext(
                userHandler, messageInfo, messageProperties, messageBody, consumer);

            var autoResetEvent = new AutoResetEvent(false);
            eventBus.Subscribe<AckEvent>(x => autoResetEvent.Set());

            handlerRunner.InvokeUserMessageHandler(context);

            autoResetEvent.WaitOne(1000);
        }
        public void SetUp()
        {
            postAckCallbackWasRun = false;

            //var logger = new ConsoleLogger();
            var logger = MockRepository.GenerateStub<IEasyNetQLogger>();
            var consumerErrorStrategy = MockRepository.GenerateStub<IConsumerErrorStrategy>();

            handlerRunner = new HandlerRunner(logger, consumerErrorStrategy);

            Func<byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) =>
                Task.Factory.StartNew(() =>
                    {
                        deliveredBody = body;
                        deliveredProperties = properties;
                        deliveredInfo = info;
                    });

            var consumer = MockRepository.GenerateStub<IBasicConsumer>();
            channel = MockRepository.GenerateStub<IModel>();
            consumer.Stub(x => x.Model).Return(channel).Repeat.Any();

            var context = new ConsumerExecutionContext(
                userHandler, messageInfo, messageProperties, messageBody, consumer);

            context.SetPostAckCallback(() => postAckCallbackWasRun = true);

            var autoResetEvent = new AutoResetEvent(false);
            ((HandlerRunner) handlerRunner).SynchronisationAction = () => autoResetEvent.Set();

            handlerRunner.InvokeUserMessageHandler(context);

            autoResetEvent.WaitOne(1000);
        }
Beispiel #7
0
        public void SetUp()
        {
            postAckCallbackWasRun = false;

            //var logger = new ConsoleLogger();
            var logger = MockRepository.GenerateStub <IEasyNetQLogger>();
            var consumerErrorStrategy = MockRepository.GenerateStub <IConsumerErrorStrategy>();

            handlerRunner = new HandlerRunner(logger, consumerErrorStrategy);

            Func <byte[], MessageProperties, MessageReceivedInfo, Task> userHandler = (body, properties, info) =>
                                                                                      Task.Factory.StartNew(() =>
            {
                deliveredBody       = body;
                deliveredProperties = properties;
                deliveredInfo       = info;
            });

            var consumer = MockRepository.GenerateStub <IBasicConsumer>();

            channel = MockRepository.GenerateStub <IModel>();
            consumer.Stub(x => x.Model).Return(channel).Repeat.Any();

            var context = new ConsumerExecutionContext(
                userHandler, messageInfo, messageProperties, messageBody, consumer);

            context.SetPostAckCallback(() => postAckCallbackWasRun = true);

            var autoResetEvent = new AutoResetEvent(false);

            ((HandlerRunner)handlerRunner).SynchronisationAction = () => autoResetEvent.Set();

            handlerRunner.InvokeUserMessageHandler(context);

            autoResetEvent.WaitOne(1000);
        }