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!!!");
                }
            }
        }
Esempio n. 2
0
        public void WorksWhenMovingToErrorQueue()
        {
            using (var messageQueue = new MsmqMessageQueue("error"))
            {
                // make sure error queue is empty
                messageQueue.PurgeInputQueue();

                adapter.Handle<Request>(req =>
                {
                    throw new ApplicationException("oh crap");
                });

                var request = new Request();
                bus.AttachHeader(request, Headers.UserName, "super-unique!!!!111");
                bus.SendLocal(request);

                // let it fail
                Thread.Sleep(2.Seconds());

                var receivedTransportMessage = messageQueue.ReceiveMessage(new NoTransaction());
                receivedTransportMessage.ShouldNotBe(null);

                var serializer = new JsonMessageSerializer();
                var message = serializer.Deserialize(receivedTransportMessage);

                message.Headers.ShouldContainKeyAndValue(Headers.UserName, "super-unique!!!!111");
            }
        }
Esempio n. 3
0
        public static IEnumerable<Message> GetMessagesFrom(string queueName)
        {
            using (var queue = new MessageQueue(MsmqUtil.GetPath(queueName)))
            {
                queue.Formatter = new RebusTransportMessageFormatter();
                queue.MessageReadPropertyFilter = RebusTransportMessageFormatter.PropertyFilter;

                bool gotMessage;

                do
                {
                    Message messageToReturn;
                    try
                    {
                        var msmqMessage = queue.Receive(3.Seconds());
                        if (msmqMessage == null)
                        {
                            yield break;
                        }
                        var receivedTransportMessage = (ReceivedTransportMessage)msmqMessage.Body;
                        var serializer = new JsonMessageSerializer();

                        messageToReturn = serializer.Deserialize(receivedTransportMessage);
                    }
                    catch (MessageQueueException exception)
                    {
                        if (exception.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout)
                        {
                            yield break;
                        }

                        throw;
                    }

                    if (messageToReturn != null)
                    {
                        gotMessage = true;
                        yield return messageToReturn;
                    }
                    else
                    {
                        gotMessage = false;
                    }
                } while (gotMessage);
            }
        }
Esempio n. 4
0
        Message GetMessageFromAuditQueue()
        {
            var timer = Stopwatch.StartNew();
            ReceivedTransportMessage receivedTransportMessage;

            var timeout = 3.Seconds();
            do
            {
                receivedTransportMessage = auditQueueReceiver.ReceiveMessage(new NoTransaction());
            } while (receivedTransportMessage == null && timer.Elapsed < timeout);

            if (receivedTransportMessage == null)
            {
                throw new TimeoutException(string.Format("No message was received within {0} timeout", timeout));
            }

            var serializer = new JsonMessageSerializer();

            return serializer.Deserialize(receivedTransportMessage);
        }