public void ItHasBeenFixed()
        {
            using (var adapter = new BuiltinContainerAdapter())
            {
                adapter.Handle<string>(s =>
                    {
                        throw new ApplicationException("Will trigger that the message gets moved to the error queue");
                    });

                Configure.With(adapter)
                         .Transport(t => t.UseRabbitMq(ConnectionString, "test.input", "test.error")
                                          .UseExchange("AlternativeExchange"))
                         .CreateBus()
                         .Start();

                adapter.Bus.SendLocal("hello there!!!");

                // wait until we're sure
                Thread.Sleep(2.Seconds());

                using (var errorQueue = new RabbitMqMessageQueue(ConnectionString, "test.error"))
                {
                    var serializer = new JsonMessageSerializer();
                    var receivedTransportMessage = errorQueue.ReceiveMessage(new NoTransaction());
                    receivedTransportMessage.ShouldNotBe(null);

                    var errorMessage = serializer.Deserialize(receivedTransportMessage);
                    errorMessage.Messages.Length.ShouldBe(1);
                    errorMessage.Messages[0].ShouldBeTypeOf<string>();
                    ((string)errorMessage.Messages[0]).ShouldBe("hello there!!!");
                }
            }
        }
Пример #2
0
        public void CanCreateAutoDeleteQueue()
        {
            const string queueName = "test.autodelete.input";
            DeleteQueue(queueName);

            // arrange
            var existedBeforeInstatiation = QueueExists(queueName);
            bool existedWhileInstantiatedAndInsideTx;
            bool existedWhileInstantiatedAndOutsideOfTx;

            // act
            using (var queue = new RabbitMqMessageQueue(ConnectionString, queueName).AutoDeleteInputQueue())
            {
                using (var scope = new TransactionScope())
                {
                    using (var txBomkarl = new TxBomkarl())
                    {
                        var willBeNull = queue.ReceiveMessage(txBomkarl);

                        existedWhileInstantiatedAndInsideTx = QueueExists(queueName);
                    }

                    existedWhileInstantiatedAndOutsideOfTx = QueueExists(queueName);
                }
            }

            var existedAfterDisposal = QueueExists(queueName);

            // assert
            existedBeforeInstatiation.ShouldBe(false);
            existedWhileInstantiatedAndInsideTx.ShouldBe(true);
            existedWhileInstantiatedAndOutsideOfTx.ShouldBe(true);
            existedAfterDisposal.ShouldBe(false);
        }
Пример #3
0
        public void AutomatiallyCreatesRecipientQueue()
        {
            // arrange
            const string senderInputQueue = "test.autocreate.sender";
            const string recipientInputQueue = "test.autocreate.recipient";
            const string someText = "whoa! as if by magic!";

            // ensure recipient queue does not exist
            DeleteQueue(senderInputQueue);
            DeleteQueue(recipientInputQueue);

            using (var sender = new RabbitMqMessageQueue(ConnectionString, senderInputQueue))
            {
                // act
                sender.Send(recipientInputQueue, new TransportMessageToSend
                    {
                        Body = Encoding.GetBytes(someText)
                    }, new NoTransaction());
            }

            using (var recipient = new RabbitMqMessageQueue(ConnectionString, recipientInputQueue))
            {
                // assert
                var receivedTransportMessage = recipient.ReceiveMessage(new NoTransaction());
                receivedTransportMessage.ShouldNotBe(null);
                Encoding.GetString(receivedTransportMessage.Body).ShouldBe(someText);
            }
        }
Пример #4
0
 static List<ReceivedTransportMessage> GetAllMessages(RabbitMqMessageQueue recipient)
 {
     var timesNullReceived = 0;
     var receivedTransportMessages = new List<ReceivedTransportMessage>();
     do
     {
         var msg = recipient.ReceiveMessage(new NoTransaction());
         if (msg == null)
         {
             timesNullReceived++;
             continue;
         }
         receivedTransportMessages.Add(msg);
     } while (timesNullReceived < 5);
     return receivedTransportMessages;
 }
Пример #5
0
        public void CanSendToQueueWithEmptyExchangeAfterAtSign()
        {
            const string recipientInputQueueName = "test.atsimbol.recipient@";
            const string senderInputQueueName = "test.atsimbol.sender";

            using (var recipientQueue = new RabbitMqMessageQueue(ConnectionString, recipientInputQueueName))
            using (var senderQueue = new RabbitMqMessageQueue(ConnectionString, senderInputQueueName))
            {
                recipientQueue.PurgeInputQueue();
                senderQueue.PurgeInputQueue();

                var id = Guid.NewGuid();
                senderQueue.Send(recipientInputQueueName,
                                 serializer.Serialize(new Message
                                 {
                                     Messages = new object[] { "HELLO WORLD!" },
                                     Headers =
                                         new Dictionary<string, object> { 
                                            { Headers.MessageId, id.ToString() }
                                         },
                                 }),
                                 new NoTransaction());

                // act
                Thread.Sleep(2.Seconds() + 1.Seconds());

                // assert
                var receivedTransportMessage = recipientQueue.ReceiveMessage(new NoTransaction());
                Assert.That(receivedTransportMessage, Is.Not.Null);
            }
        }
Пример #6
0
        public void TransportLevelMessageIdIsPreserved()
        {
            const string recipientInputQueueName = "test.tlid.recipient";
            const string senderInputQueueName = "test.tlid.sender";

            using (var recipientQueue = new RabbitMqMessageQueue(ConnectionString, recipientInputQueueName))
            using (var senderQueue = new RabbitMqMessageQueue(ConnectionString, senderInputQueueName))
            {
                recipientQueue.PurgeInputQueue();
                senderQueue.PurgeInputQueue();

                var id = Guid.NewGuid();
                senderQueue.Send(recipientInputQueueName,
                                 serializer.Serialize(new Message
                                 {
                                     Messages = new object[] { "HELLO WORLD!" },
                                     Headers =
                                         new Dictionary<string, object> { 
                                            { Headers.MessageId, id.ToString() }
                                         },
                                 }),
                                 new NoTransaction());

                // act
                Thread.Sleep(2.Seconds() + 1.Seconds());

                // assert
                var receivedTransportMessage = recipientQueue.ReceiveMessage(new NoTransaction());
                Assert.That(receivedTransportMessage, Is.Not.Null);
                Assert.That(receivedTransportMessage.Headers, Is.Not.Null);
                Assert.That(receivedTransportMessage.Headers.ContainsKey(Headers.MessageId), Is.True);
                Assert.That(receivedTransportMessage.Headers[Headers.MessageId], Is.EqualTo(id.ToString()));
            }
        }
Пример #7
0
        public void RabbitTransportDoesNotChokeOnMessagesContainingComplexHeaders()
        {
            // arrange
            const string recipientInputQueue = "test.roundtripping.receiver";
            const string someText = "whoohaa!";

            DeleteQueue(recipientInputQueue);

            // ensure recipient queue is created...
            using (var recipient = new RabbitMqMessageQueue(ConnectionString, recipientInputQueue))
            {
                // force creation of the queue
                recipient.ReceiveMessage(new NoTransaction());

                // act
                // send a message with a complex header
                using (var connection = new ConnectionFactory { Uri = ConnectionString }.CreateConnection())
                using (var model = connection.CreateModel())
                {
                    var props = model.CreateBasicProperties();
                    props.Headers = new Dictionary<string, object>
                        {
                            {
                                "someKey", new Hashtable
                                    {
                                        {"someContainedKey", "someContainedValue"},
                                        {"anotherContainedKey", "anotherContainedValue"},
                                    }
                            }
                        };

                    model.BasicPublish(recipient.ExchangeName,
                                       recipientInputQueue,
                                       props,
                                       Encoding.GetBytes(someText));
                }

                Thread.Sleep(2.Seconds());

                // assert
                var receivedTransportMessage = recipient.ReceiveMessage(new NoTransaction());
                receivedTransportMessage.ShouldNotBe(null);
                Encoding.GetString(receivedTransportMessage.Body).ShouldBe(someText);
            }

            // assert
        }
Пример #8
0
        public void MessageExpirationWorks()
        {
            // arrange
            var timeToBeReceived = 2.Seconds().ToString();

            const string recipientInputQueueName = "test.expiration.recipient";
            const string senderInputQueueName = "test.expiration.sender";

            using (var recipientQueue = new RabbitMqMessageQueue(ConnectionString, recipientInputQueueName))
            using (var senderQueue = new RabbitMqMessageQueue(ConnectionString, senderInputQueueName))
            {
                senderQueue.Send(recipientInputQueueName,
                                 serializer.Serialize(new Message
                                                          {
                                                              Messages = new object[] { "HELLO WORLD!" },
                                                              Headers =
                                                                  new Dictionary<string, object>
                                                                      {
                                                                          {
                                                                              Headers.TimeToBeReceived,
                                                                              timeToBeReceived
                                                                          }
                                                                      },
                                                          }),
                                 new NoTransaction());

                // act
                Thread.Sleep(2.Seconds() + 1.Seconds());

                // assert
                var receivedTransportMessage = recipientQueue.ReceiveMessage(new NoTransaction());
                Assert.That(receivedTransportMessage, Is.Null);
            }
        }