public async Task When_Rejecting_a_message_via_the_consumer()
        {
            //arrange
            var deadLetterReceiver = _serviceBusClient.CreateReceiver(_topicName, _channelName, new ServiceBusReceiverOptions()
            {
                SubQueue = SubQueue.DeadLetter
            });

            var producer = _producerRegistry.LookupBy(_topicName) as IAmAMessageProducerAsync;

            await producer.SendAsync(_message);

            var message = _channel.Receive(5000);

            _channel.Reject(message);

            var deadLetter = await deadLetterReceiver.ReceiveMessageAsync();

            deadLetter.MessageId.Should().Be(message.Id.ToString());
            deadLetter.CorrelationId.Should().Be(_correlationId.ToString());
            deadLetter.ContentType.Should().Be(_contentType);
            deadLetter.ApplicationProperties["HandledCount"].Should().Be(0);
            //allow for clock drift in the following test, more important to have a contemporary timestamp than anything
            deadLetter.Body.ToString().Should().Be(message.Body.Value);
        }
        public void When_a_consumer_declares_topics()
        {
            var message = new Message(
                new MessageHeader(Guid.NewGuid(), _topic, MessageType.MT_COMMAND)
            {
                PartitionKey = _partitionKey
            },
                new MessageBody($"test content [{_queueName}]"));

            bool messagePublished = false;
            var  producer         = _producerRegistry.LookupBy(_topic);
            var  producerConfirm  = producer as ISupportPublishConfirmation;

            producerConfirm.OnMessagePublished += delegate(bool success, Guid id)
            {
                if (success)
                {
                    messagePublished = true;
                }
            };

            ((IAmAMessageProducerSync)producer).Send(message);

            //Give this a chance to succeed - will fail
            Task.Delay(5000);

            messagePublished.Should().BeFalse();
        }
        public async Task When_posting_a_message_via_the_producer()
        {
            //arrange
            string testHeader      = "TestHeader";
            string testHeaderValue = "Blah!!!";

            _message.Header.Bag.Add(testHeader, testHeaderValue);

            var producer = _producerRegistry.LookupBy(_topicName) as IAmAMessageProducerAsync;

            await producer.SendAsync(_message);

            var message = _channel.Receive(5000);

            //clear the queue
            _channel.Acknowledge(message);

            message.Header.MessageType.Should().Be(MessageType.MT_COMMAND);

            message.Id.Should().Be(_command.Id);
            message.Redelivered.Should().BeFalse();
            message.Header.Id.Should().Be(_command.Id);
            message.Header.Topic.Should().Contain(_topicName);
            message.Header.CorrelationId.Should().Be(_correlationId);
            message.Header.ContentType.Should().Be(_contentType);
            message.Header.HandledCount.Should().Be(0);
            //allow for clock drift in the following test, more important to have a contemporary timestamp than anything
            message.Header.TimeStamp.Should().BeAfter(RoundToSeconds(DateTime.UtcNow.AddMinutes(-1)));
            message.Header.DelayedMilliseconds.Should().Be(0);
            //{"Id":"cd581ced-c066-4322-aeaf-d40944de8edd","Value":"Test","WasCancelled":false,"TaskCompleted":false}
            message.Body.Value.Should().Be(_message.Body.Value);
            message.Header.Bag.Should().Contain(testHeader, testHeaderValue);
        }
 private void SendMessage(Guid messageId)
 {
     ((IAmAMessageProducerSync)_producerRegistry.LookupBy(_topic)).Send(new Message(
                                                                            new MessageHeader(messageId, _topic, MessageType.MT_COMMAND)
     {
         PartitionKey = _partitionKey
     },
                                                                            new MessageBody($"test content [{_queueName}]")));
 }
        private Guid SendMessage()
        {
            var messageId = Guid.NewGuid();

            ((IAmAMessageProducerSync)_producerRegistry.LookupBy(_topic)).Send(new Message(
                                                                                   new MessageHeader(messageId, _topic, MessageType.MT_COMMAND),
                                                                                   new MessageBody($"test content [{_queueName}]")));

            return(messageId);
        }
Exemplo n.º 6
0
        public void When_requeueing_a_message()
        {
            ((IAmAMessageProducerSync)_producerRegistry.LookupBy(_topic)).Send(_message);
            var channel = _channelFactory.CreateChannel(_subscription);
            var message = channel.Receive(2000);

            channel.Requeue(message, 100);

            var requeuedMessage = channel.Receive(1000);

            //clear the queue
            channel.Acknowledge(requeuedMessage);

            requeuedMessage.Body.Value.Should().Be(message.Body.Value);
        }
        public void When_a_consumer_declares_topics()
        {
            var message = new Message(
                new MessageHeader(Guid.NewGuid(), _topic, MessageType.MT_COMMAND)
            {
                PartitionKey = _partitionKey
            },
                new MessageBody($"test content [{_queueName}]"));

            //This should fail, if consumer can't create the topic as set to Assume
            ((IAmAMessageProducerSync)_producerRegistry.LookupBy(_topic)).Send(message);

            Message[] messages = new Message[0];
            int       maxTries = 0;

            do
            {
                try
                {
                    maxTries++;
                    Task.Delay(500).Wait(); //Let topic propogate in the broker
                    messages = _consumer.Receive(10000);
                    _consumer.Acknowledge(messages[0]);

                    if (messages[0].Header.MessageType != MessageType.MT_NONE)
                    {
                        break;
                    }
                }
                catch (ChannelFailureException cfx)
                {
                    //Lots of reasons to be here as Kafka propogates a topic, or the test cluster is still initializing
                    _output.WriteLine($" Failed to read from topic:{_topic} because {cfx.Message} attempt: {maxTries}");
                }
            } while (maxTries <= 3);

            messages.Length.Should().Be(1);
            messages[0].Header.MessageType.Should().Be(MessageType.MT_COMMAND);
            messages[0].Header.PartitionKey.Should().Be(_partitionKey);
            messages[0].Body.Value.Should().Be(message.Body.Value);
        }