Exemplo n.º 1
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");
            }
        }
        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!!!");
                }
            }
        }
 protected RebusBus CreateBus(string inputQueueName, IActivateHandlers activateHandlers)
 {
     var messageQueue = new MsmqMessageQueue(inputQueueName).PurgeInputQueue();
     serializer = new JsonMessageSerializer();
     var bus = new RebusBus(activateHandlers, messageQueue, messageQueue,
                            new InMemorySubscriptionStorage(), this,
                            serializer, new SagaDataPersisterForTesting(),
                            new TrivialPipelineInspector());
     buses.Add(bus);
     return bus;
 }
Exemplo n.º 4
0
        protected override void DoSetUp()
        {
            serializer = new JsonMessageSerializer();
            senderQueue = new MsmqMessageQueue(SenderQueueName);

            destinationQueue = NewRawMsmqQueue(DestinationQueueName);

            senderQueue.PurgeInputQueue();
            destinationQueue.Purge();

            TrackDisposable(senderQueue);
        }
Exemplo n.º 5
0
 protected override void DoSetUp()
 {
     activateHandlers = new HandlerActivatorForTesting();
     determineMessageOwnership = Mock<IDetermineMessageOwnership>();
     sendMessages = Mock<ISendMessages>();
     serializeMessages = new JsonMessageSerializer();
     storeSagaData = Mock<IStoreSagaData>();
     receiveMessages = new MessageReceiverForTesting(serializeMessages);
     inspectHandlerPipeline = new TrivialPipelineInspector();
     storeSubscriptions = Mock<IStoreSubscriptions>();
     bus = CreateTheBus();
     bus.Start();
 }
Exemplo n.º 6
0
        public void SetUp()
        {
            serializer = new JsonMessageSerializer();
            senderQueue = new MsmqMessageQueue(MsmqMessageQueue.PrivateQueue("test.msmq.tx.sender"));
            destinationQueuePath = MsmqMessageQueue.PrivateQueue("test.msmq.tx.destination");

            if (!MessageQueue.Exists(destinationQueuePath))
                MessageQueue.Create(destinationQueuePath, transactional: true);

            destinationQueue = new MessageQueue(destinationQueuePath)
                                   {
                                       Formatter = new RebusTransportMessageFormatter()
                                   };

            senderQueue.PurgeInputQueue();
            destinationQueue.Purge();
        }
        protected RebusBus CreateBus(string inputQueueName, IActivateHandlers activateHandlers, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData, string errorQueueName)
        {
            var messageQueue = new MsmqMessageQueue(inputQueueName).PurgeInputQueue();
            MsmqUtil.PurgeQueue(errorQueueName);
            serializer = new JsonMessageSerializer();
            var bus = new RebusBus(activateHandlers, messageQueue, messageQueue,
                                   storeSubscriptions, storeSagaData,
                                   this, serializer, pipelineInspector,
                                   new ErrorTracker(errorQueueName),
                                   null,
                                   new ConfigureAdditionalBehavior());
            
            EnsureProperDisposal(bus);
            EnsureProperDisposal(messageQueue);

            return bus;
        }
Exemplo n.º 8
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);
            }
        }
 /// <summary>
 /// Configures Rebus to use <see cref="JsonMessageSerializer"/> to serialize messages. A <see cref="JsonSerializationOptions"/>
 /// object is returned, which can be used to configure details around how the JSON serialization should work
 /// </summary>
 public JsonSerializationOptions UseJsonSerializer()
 {
     var jsonMessageSerializer = new JsonMessageSerializer();
     Use(jsonMessageSerializer);
     return new JsonSerializationOptions(jsonMessageSerializer);
 }
 internal JsonSerializationOptions(JsonMessageSerializer jsonMessageSerializer)
 {
     this.jsonMessageSerializer = jsonMessageSerializer;
 }
Exemplo n.º 11
0
 protected override void DoSetUp()
 {
     serializer = new JsonMessageSerializer();
     RebusLoggerFactory.Current = new ConsoleLoggerFactory(true) { MinLevel = LogLevel.Info };
 }
Exemplo n.º 12
0
        public void SetUp()
        {
            disposables = new List<IDisposable>();

            serializer = new JsonMessageSerializer();
            senderQueue = new MsmqMessageQueue("test.msmq.tx.sender");
            destinationQueueName = "test.msmq.tx.destination";

            destinationQueue = NewRawMsmqQueue(destinationQueueName);

            senderQueue.PurgeInputQueue();
            destinationQueue.Purge();

            disposables.Add(senderQueue);
            disposables.Add(destinationQueue);
        }
        protected RebusBus CreateBus(string inputQueueName, IActivateHandlers activateHandlers, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData, string errorQueueName)
        {
            var messageQueue = new MsmqMessageQueue(inputQueueName, errorQueueName).PurgeInputQueue();
            MsmqUtil.PurgeQueue(errorQueueName);
            serializer = new JsonMessageSerializer();
            var bus = new RebusBus(activateHandlers, messageQueue, messageQueue,
                                   storeSubscriptions, storeSagaData,
                                   this, serializer, pipelineInspector);
            toDispose.Add(bus);
            toDispose.Add(messageQueue);

            return bus;
        }
 protected override void DoSetUp()
 {
     serializer = new JsonMessageSerializer();
 }
Exemplo n.º 15
0
        public void SetUp()
        {
            serializer = new JsonMessageSerializer();
            senderQueue = new MsmqMessageQueue("test.msmq.tx.sender", "error");
            destinationQueueName = "test.msmq.tx.destination";
            destinationQueuePath = MsmqMessageQueue.PrivateQueue(destinationQueueName);

            if (!MessageQueue.Exists(destinationQueuePath))
            {
                var messageQueue = MessageQueue.Create(destinationQueuePath, transactional: true);
                messageQueue.SetPermissions(Thread.CurrentPrincipal.Identity.Name, MessageQueueAccessRights.FullControl);
            }

            destinationQueue = new MessageQueue(destinationQueuePath)
                                   {
                                       Formatter = new RebusTransportMessageFormatter(),
                                       MessageReadPropertyFilter = RebusTransportMessageFormatter.PropertyFilter,
                                   };

            senderQueue.PurgeInputQueue();
            destinationQueue.Purge();
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
0
 public JsonSerializationOptions(JsonMessageSerializer jsonMessageSerializer)
 {
     this.jsonMessageSerializer = jsonMessageSerializer;
 }
 public MessageReceiverForTesting(JsonMessageSerializer serializer)
 {
     this.serializer = serializer;
 }
Exemplo n.º 19
0
 public JsonSerializationOptions UseJsonSerializer()
 {
     var jsonMessageSerializer = new JsonMessageSerializer();
     Backbone.SerializeMessages = jsonMessageSerializer;
     return new JsonSerializationOptions(jsonMessageSerializer);
 }