public void When_a_message_consumer_reads_multiple_messages() { var messageOne = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, CONTENT_TYPE), new MessageBody("test content one") ); var messageTwo = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, CONTENT_TYPE), new MessageBody("test content two") ); var messageThree = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, CONTENT_TYPE), new MessageBody("test content three") ); var messageFour = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, CONTENT_TYPE), new MessageBody("test content four") ); //send MESSAGE_COUNT messages _messageProducer.Send(messageOne); _messageProducer.Send(messageTwo); _messageProducer.Send(messageThree); _messageProducer.Send(messageFour); int messagesRecieved = 0; do { var outstandingMessageCount = MESSAGE_COUNT - messagesRecieved; //retrieve messages var moreMessages = _consumer.Receive(10000); moreMessages.Length.Should().BeLessOrEqualTo(outstandingMessageCount); //should not receive more than buffer in one hit moreMessages.Length.Should().BeLessOrEqualTo(BUFFER_SIZE); foreach (var message in moreMessages) { //this will be MT_NONE for an empty message message.Header.MessageType.Should().Be(MessageType.MT_COMMAND); _consumer.Acknowledge(message); } messagesRecieved += moreMessages.Length; } while (messagesRecieved < MESSAGE_COUNT); }
public void When_posting_a_message_via_the_producer() { //arrange _messageProducer.Send(_message); var message = _channel.Receive(1000); //clear the queue _channel.Acknowledge(message); //should_send_the_message_to_aws_sqs message.Header.MessageType.Should().Be(MessageType.MT_COMMAND); message.Id.Should().Be(_myCommand.Id); message.Redelivered.Should().BeFalse(); message.Header.Id.Should().Be(_myCommand.Id); message.Header.Topic.Should().Contain(_topicName); message.Header.CorrelationId.Should().Be(_correlationId); message.Header.ReplyTo.Should().Be(_replyTo); 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); }
public void When_raw_message_delivery_disabled() { //arrange var messageHeader = new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, correlationId: Guid.NewGuid(), replyTo: string.Empty, contentType: "text\\plain"); var customHeaderItem = new KeyValuePair <string, object>("custom-header-item", "custom-header-item-value"); messageHeader.Bag.Add(customHeaderItem.Key, customHeaderItem.Value); var messageToSent = new Message(messageHeader, new MessageBody("test content one")); //act _messageProducer.Send(messageToSent); var messageReceived = _channel.Receive(10000); _channel.Acknowledge(messageReceived); //assert messageReceived.Id.Should().Be(messageToSent.Id); messageReceived.Header.Topic.Should().Be(messageToSent.Header.Topic); messageReceived.Header.MessageType.Should().Be(messageToSent.Header.MessageType); messageReceived.Header.CorrelationId.Should().Be(messageToSent.Header.CorrelationId); messageReceived.Header.ReplyTo.Should().Be(messageToSent.Header.ReplyTo); messageReceived.Header.ContentType.Should().Be(messageToSent.Header.ContentType); messageReceived.Header.Bag.Should().ContainKey(customHeaderItem.Key).And.ContainValue(customHeaderItem.Value); messageReceived.Body.Value.Should().Be(messageToSent.Body.Value); }
public void When_posting_a_message_via_the_messaging_gateway() { _messageProducer.Send(_message); _listenedMessage = _queueListener.Listen(); //should_send_the_message_to_aws_sqs Assert.NotNull(_listenedMessage.Body); }
public void When_posting_a_message_via_the_messaging_gateway_and_sns_topic_does_not_exist() { _messageProducer.Send(_message); _topic = _queueListener.CheckSnsTopic(_message.Header.Topic); //should_create_topic_and_send_the_message _topic.Should().NotBeNull(); }
public void When_purging_the_queue() { //arange _messageProducer.Send(_message); _channel.Purge(); //act var message = _channel.Receive(100); //assert message.Header.MessageType.Should().Be(MessageType.MT_NONE); }
public void When_infastructure_exists_can_verify() { //arrange _messageProducer.Send(_message); var messages = _consumer.Receive(1000); //Assert var message = messages.First(); message.Id.Should().Be(_myCommand.Id); //clear the queue _consumer.Acknowledge(message); }
public void When_rejecting_a_message_through_gateway_with_requeue() { _messageProducer.Send(_message); var message = _channel.Receive(1000); _channel.Reject(message); //should requeue_the_message message = _channel.Receive(3000); //clear the queue _channel.Acknowledge(message); message.Id.Should().Be(_myCommand.Id); }
public void When_topic_missing_verify_throws() { //arrange var producer = new SqsMessageProducer(_awsConnection, new SnsPublication { MakeChannels = OnMissingChannel.Validate }); //act && assert Assert.Throws <BrokerUnreachableException>(() => producer.Send(new Message( new MessageHeader { Topic = _routingKey, ContentType = "plain/text" }, new MessageBody("Test")))); }
public void When_requeueing_redrives_to_the_queue() { _sender.Send(_message); var receivedMessage = _channel.Receive(5000); _channel.Requeue(receivedMessage ); receivedMessage = _channel.Receive(5000); _channel.Requeue(receivedMessage ); //should force us into the dlq receivedMessage = _channel.Receive(5000); _channel.Requeue(receivedMessage) ; Task.Delay(5000); //inspect the dlq GetDLQCount(_dlqChannelName).Should().Be(1); }
public void When_rejecting_a_message_through_gateway_with_requeue() { _messageProducer.Send(_message); var message = _channel.Receive(5000); _channel.Reject(message); //Let the timeout change Task.Delay(TimeSpan.FromMilliseconds(3000)); //should requeue_the_message message = _channel.Receive(5000); //clear the queue _channel.Acknowledge(message); message.Id.Should().Be(_myCommand.Id); }
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 void When_a_message_consumer_reads_multiple_messages() { var messageOne = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, _contentType), new MessageBody("test content one") ); var messageTwo = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, _contentType), new MessageBody("test content two") ); var messageThree = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, _contentType), new MessageBody("test content three") ); var messageFour = new Message( new MessageHeader(Guid.NewGuid(), _topicName, MessageType.MT_COMMAND, Guid.NewGuid(), string.Empty, _contentType), new MessageBody("test content four") ); //send MESSAGE_COUNT messages _messageProducer.Send(messageOne); _messageProducer.Send(messageTwo); _messageProducer.Send(messageThree); _messageProducer.Send(messageFour); int iteration = 0; var messagesReceived = new List <Message>(); var messagesReceivedCount = messagesReceived.Count; do { iteration++; var outstandingMessageCount = _messageCount - messagesReceivedCount; //retrieve messages var messages = _consumer.Receive(10000); messages.Length.Should().BeLessOrEqualTo(outstandingMessageCount); //should not receive more than buffer in one hit messages.Length.Should().BeLessOrEqualTo(_bufferSize); var moreMessages = messages.Where(m => m.Header.MessageType == MessageType.MT_COMMAND); foreach (var message in moreMessages) { messagesReceived.Add(message); _consumer.Acknowledge(message); } messagesReceivedCount = messagesReceived.Count; Task.Delay(1000).Wait(); } while ((iteration <= 5) && (messagesReceivedCount < _messageCount)); messagesReceivedCount.Should().Be(4); }