Ejemplo n.º 1
0
        public void When_retry_limits_force_a_message_onto_the_dlq()
        {
            //NOTE: This test is **slow** because it needs to ensure infrastructure and then wait whilst we requeue a message a number of times,
            //then propagate to the DLQ

            //start a message pump, let it create infrastructure
            var task = Task.Factory.StartNew(() => _messagePump.Run(), TaskCreationOptions.LongRunning);

            Task.Delay(20000).Wait();

            //put something on an SNS topic, which will be delivered to our SQS queue
            _sender.Send(_message);

            //Let the message be handled and deferred until it reaches the DLQ
            Task.Delay(20000).Wait();

            //send a quit message to the pump to terminate it
            var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody(""));

            _channel.Enqueue(quitMessage);

            //wait for the pump to stop once it gets a quit message
            Task.WaitAll(new[] { task });

            Task.Delay(5000).Wait();

            //inspect the dlq
            var dlqMessage = _deadLetterConsumer.Receive(10000).First();

            //assert this is our message
            dlqMessage.Body.Value.Should().Be(_message.Body.Value);

            _deadLetterConsumer.Acknowledge(dlqMessage);
        }
Ejemplo n.º 2
0
        public void When_the_buffer_is_not_empty_read_from_that_before_receiving()
        {
            _channel.Enqueue(_messageOne, _messageTwo);

            _messageThree = new Message(
                new MessageHeader(Guid.NewGuid(), "key", MessageType.MT_EVENT),
                new MessageBody("ThirdMessage"));

            A.CallTo(() => _gateway.Receive(10)).Returns(new Message[] { _messageThree });

            //pull the first message enqueued from the buffer
            _channel.Receive(10).Id.Should().Be(_messageOne.Id);
            //pull the second message enqueued from the buffer
            _channel.Receive(10).Id.Should().Be(_messageTwo.Id);
            //now we pull from the queue as the buffer is empty
            _channel.Receive(10).Id.Should().Be(_messageThree.Id);
            A.CallTo(() => _gateway.Receive(10)).MustHaveHappened();
        }
        public void When_throwing_defer_action_respect_redrive()
        {
            //put something on an SNS topic, which will be delivered to our SQS queue
            _sender.Send(_message);

            //start a message pump, let it process messages
            var task = Task.Factory.StartNew(() => _messagePump.Run(), TaskCreationOptions.LongRunning);

            Task.Delay(5000).Wait();

            //send a quit message to the pump to terminate it
            var quitMessage = new Message(new MessageHeader(Guid.Empty, "", MessageType.MT_QUIT), new MessageBody(""));

            _channel.Enqueue(quitMessage);

            //wait for the pump to stop once it gets a quit message
            Task.WaitAll(new[] { task });

            Task.Delay(5000);

            //inspect the dlq
            GetDLQCount(_dlqChannelName).Should().Be(1);
        }
 public override void Post(SendOrPostCallback callback, object state)
 {
     _channel.Enqueue(new Message(new MessageHeader(), new MessageBody(new PostBackItem(callback, state))));
 }