예제 #1
0
        /// <summary>
        /// Requeues the specified message.
        /// </summary>
        /// <param name="message"></param>
        /// <param name="delayMilliseconds">Number of milliseconds to delay delivery of the message.</param>
        /// <returns>True if the message should be acked, false otherwise</returns>
        public bool Requeue(Message message, int delayMilliseconds)
        {
            var topic = message.Header.Topic;

            s_logger.LogInformation("Requeuing message with topic {Topic} and id {Id}.", topic, message.Id);

            if (delayMilliseconds > 0)
            {
                _messageProducerSync.SendWithDelay(message, delayMilliseconds);
            }
            else
            {
                _messageProducerSync.Send(message);
            }
            Acknowledge(message);

            return(true);
        }
예제 #2
0
        public void When_reading_a_delayed_message_via_the_messaging_gateway()
        {
            _messageProducer.SendWithDelay(_message, 3000);

            var immediateResult      = _messageConsumer.Receive(0).First();
            var deliveredWithoutWait = immediateResult.Header.MessageType == MessageType.MT_NONE;

            immediateResult.Header.HandledCount.Should().Be(0);
            immediateResult.Header.DelayedMilliseconds.Should().Be(0);

            //_should_have_not_been_able_get_message_before_delay
            deliveredWithoutWait.Should().BeTrue();

            var delayedResult = _messageConsumer.Receive(10000).First();


            //_should_send_a_message_via_rmq_with_the_matching_body
            delayedResult.Body.Value.Should().Be(_message.Body.Value);
            delayedResult.Header.MessageType.Should().Be(MessageType.MT_COMMAND);
            delayedResult.Header.HandledCount.Should().Be(0);
            delayedResult.Header.DelayedMilliseconds.Should().Be(3000);

            _messageConsumer.Acknowledge(delayedResult);
        }