コード例 #1
0
        private BlockingQueueConsumer CreateConsumer(IConnectionFactory connectionFactory)
        {
            var consumer = new BlockingQueueConsumer(
                connectionFactory,
                new DefaultMessageHeadersConverter(),
                new ActiveObjectCounter <BlockingQueueConsumer>(),
                AcknowledgeMode.AUTO,
                true,
                1,
                null,
                queue.QueueName);

            consumer.Start();

            var n = 0;

            while (n++ < 100)
            {
                if (consumer.CurrentConsumers().Count > 0)
                {
                    break;
                }

                Thread.Sleep(100);
            }

            return(consumer);
        }
コード例 #2
0
        /// <summary>Creates the consumer.</summary>
        /// <param name="accessor">The accessor.</param>
        /// <returns>The consumer.</returns>
        private BlockingQueueConsumer CreateConsumer(RabbitAccessor accessor)
        {
            var consumer = new BlockingQueueConsumer(accessor.ConnectionFactory, new DefaultMessagePropertiesConverter(), new ActiveObjectCounter <BlockingQueueConsumer>(), AcknowledgeModeUtils.AcknowledgeMode.Auto, true, 1, queue.Name);

            consumer.Start();

            // wait for consumeOk...
            var n = 0;

            while (n++ < 100)
            {
                if (consumer.ConsumerTag == null)
                {
                    try
                    {
                        Thread.Sleep(100);
                    }
                    catch (ThreadInterruptedException e)
                    {
                        Thread.CurrentThread.Interrupt();
                        break;
                    }
                }
            }

            return(consumer);
        }
コード例 #3
0
        private void TestRequeueOrNot(Exception ex, bool requeue)
        {
            var connectionFactory     = new Mock <IConnectionFactory>();
            var channel               = new Mock <IModel>();
            var blockingQueueConsumer = new BlockingQueueConsumer(
                connectionFactory.Object, new DefaultMessagePropertiesConverter(), new ActiveObjectCounter <BlockingQueueConsumer>(), AcknowledgeModeUtils.AcknowledgeMode.Auto, true, 1, "testQ");

            this.TestRequeueOrNotGuts(ex, requeue, channel, blockingQueueConsumer);
        }
コード例 #4
0
        private string GetResult(BlockingQueueConsumer consumer, bool expected)
        {
            var response = consumer.NextMessage(expected ? 2000 : 100);

            if (response == null)
            {
                return(null);
            }

            return(new Rabbit.Support.Converter.SimpleMessageConverter().FromMessage <string>(response));
        }
コード例 #5
0
        /// <summary>Gets the result.</summary>
        /// <param name="consumer">The consumer.</param>
        /// <returns>The result.</returns>
        private string GetResult(BlockingQueueConsumer consumer)
        {
            var response = consumer.NextMessage(200);

            if (response == null)
            {
                return(null);
            }

            return((string)new SimpleMessageConverter().FromMessage(response));
        }
コード例 #6
0
        public void Start()
        {
            AsyncEventSettings settings = new AsyncEventSettings();

            _consumer = new BlockingQueueConsumer();
            _server   = new AsyncEventServer(IPAddress.IPv6Any, 2345, _consumer, settings);
            _server.Start();
            _consumerThread      = new Thread(HandleEvents);
            _consumerThread.Name = "ConsumerThread";
            _consumerThread.Start();
        }
コード例 #7
0
        public void TestTransactionalLowLevel()
        {
            var template          = new RabbitTemplate();
            var connectionFactory = new CachingConnectionFactory();

            connectionFactory.Port     = BrokerTestUtils.GetPort();
            template.ConnectionFactory = connectionFactory;

            var blockingQueueConsumer = new BlockingQueueConsumer(connectionFactory, new DefaultMessagePropertiesConverter(), new ActiveObjectCounter <BlockingQueueConsumer>(), AcknowledgeModeUtils.AcknowledgeMode.Auto, true, 1, queue.Name);

            blockingQueueConsumer.Start();
            connectionFactory.Dispose();

            // TODO: make this into a proper assertion. An exception can be thrown here by the Rabbit client and printed to
            // stderr without being rethrown (so hard to make a test fail).
            blockingQueueConsumer.Stop();
            Assert.IsNull(template.ReceiveAndConvert(queue.Name));
        }
コード例 #8
0
        private void TestRequeueOrNotGuts(Exception ex, bool requeue, Mock <IModel> channel, BlockingQueueConsumer blockingQueueConsumer)
        {
            var channelField = typeof(BlockingQueueConsumer).GetField("channel", BindingFlags.NonPublic | BindingFlags.Instance);

            channelField.SetValue(blockingQueueConsumer, channel.Object);

            var deliveryTags = new LinkedList <long>();

            deliveryTags.AddOrUpdate(1L);
            var deliveryTagsField = typeof(BlockingQueueConsumer).GetField("deliveryTags", BindingFlags.NonPublic | BindingFlags.Instance);

            deliveryTagsField.SetValue(blockingQueueConsumer, deliveryTags);
            blockingQueueConsumer.RollbackOnExceptionIfNecessary(ex);
            channel.Verify(m => m.BasicReject(1L, requeue), Times.Once());
        }