Пример #1
0
        private void HandleStandardMessage(OpenedQueue queue, Message message)
        {
            var worker = readyForWork.Dequeue();

            if (worker == null)             // handle message later
            {
                queue.Send(message);

                continuousDeliveryFailures++;

                if (continuousDeliveryFailures >= 100)
                {
                    System.Threading.Thread.Sleep(1000);
                    continuousDeliveryFailures = 0;
                }
            }
            else
            {
                continuousDeliveryFailures = 0;
                var workerEndpoint = endpointRouter.GetRoutedEndpoint(worker);
                using (var workerQueue = MsmqUtil.GetQueuePath(workerEndpoint).Open(QueueAccessMode.Send))
                {
                    logger.DebugFormat("Dispatching message '{0}' to {1}", message.Id, workerEndpoint.Uri);
                    workerQueue.Send(message);
                }
            }
        }
Пример #2
0
 private void RemoveAllReadyToWorkMessages()
 {
     using (var tx = new TransactionScope())
         using (var readyForWorkQueue = MsmqUtil.GetQueuePath(Endpoint).Open(QueueAccessMode.SendAndReceive))
             using (var enumerator = readyForWorkQueue.GetMessageEnumerator2())
             {
                 try
                 {
                     while (enumerator.MoveNext())
                     {
                         while (
                             enumerator.Current != null &&
                             enumerator.Current.Label == typeof(ReadyToWork).FullName)
                         {
                             var current = enumerator.RemoveCurrent(readyForWorkQueue.GetTransactionType());
                             HandleLoadBalancerMessage(readyForWorkQueue, current);
                         }
                     }
                 }
                 catch (MessageQueueException e)
                 {
                     if (e.MessageQueueErrorCode != MessageQueueErrorCode.IOTimeout)
                     {
                         throw;
                     }
                 }
                 readyForWork.Clear();
                 tx.Complete();
             }
 }
Пример #3
0
        public MsmqFlatQueueTestBase()
        {
            defaultTestBase = new MsmqTestBase();

            testQueueEndPoint = new Endpoint
            {
                Uri = new Uri("msmq://localhost/test_queue")
            };
            testQueuePath = MsmqUtil.GetQueuePath(testQueueEndPoint).QueuePath;

            transactionalTestQueueEndpoint = new Endpoint
            {
                Uri = new Uri("msmq://localhost/transactional_test_queue")
            };
            transactionalTestQueuePath = MsmqUtil.GetQueuePath(transactionalTestQueueEndpoint).QueuePath;

            subscriptionsEndpoint = new Endpoint
            {
                Uri = new Uri(testQueueEndPoint.Uri + "#" + subscriptions)
            };
            subscriptionQueuePath = MsmqUtil.GetQueuePath(subscriptionsEndpoint).QueuePath;


            SetupQueues();

            queue = MsmqUtil.GetQueuePath(testQueueEndPoint).Open();
            transactionalQueue = MsmqUtil.GetQueuePath(transactionalTestQueueEndpoint).Open();
            subscriptions      = MsmqUtil.GetQueuePath(subscriptionsEndpoint).Open(QueueAccessMode.SendAndReceive,
                                                                                   new XmlMessageFormatter(new[]
            {
                typeof(string)
            }));
        }
Пример #4
0
        private void SendToAllWorkers(Message message, string logMessage)
        {
            var values = KnownWorkers.GetValues();

            foreach (var worker in values)
            {
                var workerEndpoint = endpointRouter.GetRoutedEndpoint(worker);
                using (var workerQueue = MsmqUtil.GetQueuePath(workerEndpoint).Open(QueueAccessMode.Send))
                {
                    logger.DebugFormat(logMessage, Endpoint.Uri, worker);
                    workerQueue.Send(message);
                }
            }
            if (values.Length == 0)
            {
                return;
            }

            var copy = MessageBatchSentToAllWorkers;

            if (copy != null)
            {
                copy(message);
            }
        }
Пример #5
0
        public void LoadBalancer_is_singleton()
        {
            var queuePath = MsmqUtil.GetQueuePath(new Endpoint
            {
                Uri = new Uri("msmq://localhost/test.balancer")
            });
            var queueAcceptingPath = MsmqUtil.GetQueuePath(new Endpoint
            {
                Uri = new Uri("msmq://localhost/test.balancer.acceptingwork")
            });

            if (MessageQueue.Exists(queuePath.QueuePath) == false)
            {
                MessageQueue.Create(queuePath.QueuePath);
            }
            if (MessageQueue.Exists(queueAcceptingPath.QueuePath) == false)
            {
                MessageQueue.Create(queueAcceptingPath.QueuePath);
            }

            new LoadBalancerConfiguration()
            .UseAutofac(container)
            .UseStandaloneConfigurationFile("LoadBalancer.config")
            .Configure();

            var startable    = container.Resolve <IStartable>();
            var loadBalancer = container.Resolve <MsmqLoadBalancer>();

            Assert.Same(startable, loadBalancer);
        }
Пример #6
0
        protected override void BeforeStart(OpenedQueue queue)
        {
            try
            {
                queueStrategy.InitializeQueue(Endpoint, QueueType.LoadBalancer);
            }
            catch (Exception e)
            {
                throw new TransportException(
                          "Could not open queue for load balancer: " + Endpoint + Environment.NewLine +
                          "Queue path: " + MsmqUtil.GetQueuePath(Endpoint), e);
            }

            try
            {
                ReadUrisFromSubQueue(KnownWorkers, SubQueue.Workers);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Could not read workers subqueue", e);
            }

            try
            {
                ReadUrisFromSubQueue(KnownEndpoints, SubQueue.Endpoints);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Could not read endpoints subqueue", e);
            }

            RemoveAllReadyToWorkMessages();
        }
Пример #7
0
        public void Dispose()
        {
            var endpointQueue = MsmqUtil.GetQueuePath(_endpoint);

            if (endpointQueue.Exists)
            {
                endpointQueue.Delete();
            }
        }
Пример #8
0
        public static void Prepare(string queueName, QueueType queueType)
        {
            var queueUri  = new Uri(queueName);
            var queuePath = MsmqUtil.GetQueuePath(new Endpoint {
                Uri = queueUri
            });

            CreateQueueIfNotExists(queuePath.QueuePath);
            //PurgeQueue(queuePath.QueuePath);
            //PurgeSubqueues(queuePath.QueuePath, queueType);
        }
        public void Will_be_translated_correctly()
        {
            const string privateQueue = @"FormatName:PRIVATE=0786bae3-b81d-48a4-9f84-413800f09f08\00000010";
            var          uri          = MsmqUtil.GetQueueUri(new MessageQueue(privateQueue));

            Assert.Equal("msmq://0786bae3-b81d-48a4-9f84-413800f09f08/00000010",
                         uri.ToString());
            Assert.Equal(privateQueue,
                         MsmqUtil.GetQueuePath(new Endpoint {
                Uri = uri
            }).QueuePath);
        }
Пример #10
0
 public void Should_create_subqueue_strategy_queues()
 {
     container = new WindsorContainer(new XmlInterpreter(
                                          Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "InitBus.config")
                                          ));
     container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());
     using (var bus = container.Resolve <IStartableServiceBus>())
     {
         bus.Start();
         Assert.True(MsmqUtil.GetQueuePath(endPoint).Exists);
     }
 }
Пример #11
0
 public void Should_create_subqueue_strategy_queues()
 {
     container = new WindsorContainer(new XmlInterpreter());
     new RhinoServiceBusConfiguration()
     .UseCastleWindsor(container)
     .UseStandaloneConfigurationFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "InitBus.config"))
     .Configure();
     using (var bus = container.Resolve <IStartableServiceBus>())
     {
         bus.Start();
         Assert.True(MsmqUtil.GetQueuePath(endPoint).Exists);
     }
 }
Пример #12
0
 private void ReadUrisFromSubQueue(Set <Uri> set, SubQueue subQueue)
 {
     using (var q = MsmqUtil.GetQueuePath(Endpoint).Open(QueueAccessMode.Receive))
         using (var sq = q.OpenSubQueue(subQueue, QueueAccessMode.SendAndReceive))
         {
             var messages = sq.GetAllMessagesWithStringFormatter();
             foreach (var message in messages)
             {
                 var uriString = message.Body.ToString();
                 set.Add(new Uri(uriString));
             }
         }
 }
Пример #13
0
        public void Endpoint_queue_is_created_on_start()
        {
            var host = new DefaultHost();

            host.BusConfiguration(config => config.Bus(EndpointUri));

            host.Start <AutofacTestBootStrapper>();
            host.Dispose();

            var endpointQueue = MsmqUtil.GetQueuePath(_endpoint);

            Assert.True(endpointQueue.Exists);
        }
Пример #14
0
        public void Init(ITransport transport, IServiceBus bus)
        {
            var endpoint  = endpointRouter.GetRoutedEndpoint(logQueue);
            var queueInfo = MsmqUtil.GetQueuePath(endpoint);

            queueInfo.Create();
            queue = queueInfo.Open(QueueAccessMode.Send);

            transport.MessageArrived                += Transport_OnMessageArrived;
            transport.MessageProcessingFailure      += Transport_OnMessageProcessingFailure;
            transport.MessageProcessingCompleted    += Transport_OnMessageProcessingCompleted;
            transport.MessageSerializationException += Transport_OnMessageSerializationException;
            transport.MessageSent += Transport_OnMessageSent;
        }
Пример #15
0
        public override void Execute(string user)
        {
            // will create the queues if they are not already there
            messageLoggingModule.Init(transport, null);
            var queuePath = MsmqUtil.GetQueuePath(new Endpoint
            {
                Uri = messageLoggingModule.LogQueue
            }).QueuePath;

            using (var queue = new MessageQueue(queuePath))
            {
                GrantPermissions(queue, user);
            }
        }
Пример #16
0
        public Full_test_of_load_balancer_and_failover_and_recovery()
        {
            var loadBalancerQueuePathUri = new Uri(loadBalancerQueue).ToEndpoint().Uri;
            var lb2Endpoint               = new Uri("msmq://localhost/test_queue.balancer2").ToEndpoint();
            var loadBalancerQueuePath2    = MsmqUtil.GetQueuePath(lb2Endpoint).QueuePath;
            var loadBalancerQueuePathUri2 = lb2Endpoint.Uri;

            if (MessageQueue.Exists(loadBalancerQueuePath2))
            {
                MessageQueue.Delete(loadBalancerQueuePath2);
            }
            MessageQueue.Create(loadBalancerQueuePath2, true);

            container = new WindsorContainer();
            new RhinoServiceBusConfiguration()
            .UseCastleWindsor(container)
            .UseStandaloneConfigurationFile(@"LoadBalancer\SendingBusToLoadBalancer.config")
            .Configure();
            container.Register(
                Component.For <MsmqLoadBalancer>()
                .DependsOn(new
            {
                endpointRouter        = new EndpointRouter(),
                threadCount           = 1,
                endpoint              = loadBalancerQueuePathUri,
                secondaryLoadBalancer = loadBalancerQueuePathUri2,
                transactional         = TransactionalOptions.FigureItOut,
                messageBuilder        = new MsmqMessageBuilder(new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(container)), new CastleServiceLocator(container))
            }).LifeStyle.Transient,
                Component.For <MsmqSecondaryLoadBalancer>()
                .DependsOn(new
            {
                endpointRouter      = new EndpointRouter(),
                threadCount         = 1,
                endpoint            = loadBalancerQueuePathUri2,
                primaryLoadBalancer = loadBalancerQueuePathUri,
                transactional       = TransactionalOptions.FigureItOut,
                messageBuilder      = new MsmqMessageBuilder(new XmlMessageSerializer(new DefaultReflection(), new CastleServiceLocator(container)), new CastleServiceLocator(container))
            })
                );

            //New conatainer to more closely mimic as separate app.
            receivingBusContainer = new WindsorContainer();
            new RhinoServiceBusConfiguration()
            .UseCastleWindsor(receivingBusContainer)
            .UseStandaloneConfigurationFile(@"LoadBalancer\ReceivingBusWithLoadBalancer.config")
            .Configure();
            receivingBusContainer.Register(Component.For <TestHandler>());
        }
        public void Error_subqeueue_will_contain_error_details()
        {
            using (var bus = container.Resolve <IStartableServiceBus>())
            {
                bus.Start();

                bus.Send(bus.Endpoint, DateTime.Now);

                using (var q = MsmqUtil.GetQueuePath(bus.Endpoint).Open())
                    using (var errorSubQueue = q.OpenSubQueue(SubQueue.Errors, QueueAccessMode.SendAndReceive))
                    {
                        var originalMessage   = errorSubQueue.Receive();
                        var errorDescripotion = errorSubQueue.Receive();
                        Assert.Equal("Error description for: " + originalMessage.Label, errorDescripotion.Label);
                    }
            }
        }
Пример #18
0
        public void Should_create_flat_queue_strategy_queues()
        {
            container = new WindsorContainer(new XmlInterpreter(
                                                 Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "InitBus.config")
                                                 ));
            container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility().UseFlatQueueStructure());
            using (var bus = container.Resolve <IStartableServiceBus>())
            {
                bus.Start();

                Assert.True(MsmqUtil.GetQueuePath(endPoint).Exists);
                Assert.True(MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#subscriptions"));
                Assert.True(MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#errors"));
                Assert.True(MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#discarded"));
                Assert.True(MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#timeout"));
            }
            CleanQueue();
        }
Пример #19
0
        private void HandleStandardMessage(OpenedQueue queue, Message message)
        {
            var worker = readyForWork.Dequeue();

            if (worker == null)             // handle message later
            {
                queue.Send(message);
            }
            else
            {
                var workerEndpoint = endpointRouter.GetRoutedEndpoint(worker);
                using (var workerQueue = MsmqUtil.GetQueuePath(workerEndpoint).Open(QueueAccessMode.Send))
                {
                    logger.DebugFormat("Dispatching message '{0}' to {1}", message.Id, workerEndpoint.Uri);
                    workerQueue.Send(message);
                }
            }
        }
Пример #20
0
        public void Will_send_administrative_messages_to_all_nodes()
        {
            using (var loadBalancer = container.Resolve <MsmqLoadBalancer>())
                using (var bus = container.Resolve <IStartableServiceBus>())
                {
                    var wait = new ManualResetEvent(false);

                    loadBalancer.MessageBatchSentToAllWorkers += message => wait.Set();

                    loadBalancer.Start();
                    bus.Start();

                    bus.Send(loadBalancer.Endpoint, new ReadyToWork
                    {
                        Endpoint = TransactionalTestQueueUri.Uri
                    });

                    bus.Send(loadBalancer.Endpoint, new ReadyToWork
                    {
                        Endpoint = TestQueueUri2.Uri
                    });

                    bus.Send(loadBalancer.Endpoint, new AddSubscription
                    {
                        Endpoint = bus.Endpoint,
                        Type     = "foobar"
                    });

                    wait.WaitOne(TimeSpan.FromSeconds(30), false);
                }

            using (var q = MsmqUtil.GetQueuePath(TransactionalTestQueueUri).Open())
            {
                var message = q.Receive();
                Assert.Equal("Rhino.ServiceBus.Messages.AddSubscription", message.Label);
            }

            using (var q = MsmqUtil.GetQueuePath(TestQueueUri2).Open())
            {
                var message = q.Receive();
                Assert.Equal("Rhino.ServiceBus.Messages.AddSubscription", message.Label);
            }
        }
        public Full_test_of_load_balancer_and_failover_and_recovery()
        {
            var loadBalancerQueuePathUri = new Uri(loadBalancerQueue).ToEndpoint().Uri;
            var lb2Endpoint               = new Uri("msmq://localhost/test_queue.balancer2").ToEndpoint();
            var loadBalancerQueuePath2    = MsmqUtil.GetQueuePath(lb2Endpoint).QueuePath;
            var loadBalancerQueuePathUri2 = lb2Endpoint.Uri;

            if (MessageQueue.Exists(loadBalancerQueuePath2))
            {
                MessageQueue.Delete(loadBalancerQueuePath2);
            }
            MessageQueue.Create(loadBalancerQueuePath2, true);

            container = new WindsorContainer(new XmlInterpreter(@"LoadBalancer\SendingBusToLoadBalancer.config"));
            container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());
            container.Register(
                Component.For <MsmqLoadBalancer>()
                .DependsOn(new
            {
                endpointRouter        = new EndpointRouter(),
                threadCount           = 1,
                endpoint              = loadBalancerQueuePathUri,
                secondaryLoadBalancer = loadBalancerQueuePathUri2,
                transactional         = TransactionalOptions.FigureItOut
            }).LifeStyle.Transient,
                Component.For <MsmqSecondaryLoadBalancer>()
                .DependsOn(new
            {
                endpointRouter      = new EndpointRouter(),
                threadCount         = 1,
                endpoint            = loadBalancerQueuePathUri2,
                primaryLoadBalancer = loadBalancerQueuePathUri,
                transactional       = TransactionalOptions.FigureItOut
            })
                );

            //New conatainer to more closely mimic as separate app.
            receivingBusContainer = new WindsorContainer(new XmlInterpreter(@"LoadBalancer\ReceivingBusWithLoadBalancer.config"));
            receivingBusContainer.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());
            receivingBusContainer.AddComponent <TestHandler>();
        }
Пример #22
0
        private void CleanQueue()
        {
            MsmqUtil.GetQueuePath(endPoint).Delete();

            if (MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#subscriptions"))
            {
                MessageQueue.Delete(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#subscriptions");
            }
            if (MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#errors"))
            {
                MessageQueue.Delete(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#errors");
            }
            if (MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#discarded"))
            {
                MessageQueue.Delete(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#discarded");
            }
            if (MessageQueue.Exists(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#timeout"))
            {
                MessageQueue.Delete(MsmqUtil.GetQueuePath(endPoint).QueuePath + "#timeout");
            }
        }
Пример #23
0
        public void When_load_balancer_starts_will_read_known_endpoints_from_endpoints_sub_queue()
        {
            using (var endPointsQueue = MsmqUtil.GetQueuePath(loadBalancerEndpoint)
                                        .Open(QueueAccessMode.SendAndReceive,
                                              new XmlMessageFormatter(new[]
            {
                typeof(string)
            })))
            {
                endPointsQueue.Send(new Message(TestQueueUri.Uri.ToString()));
                var    peek = endPointsQueue.Peek(TimeSpan.FromSeconds(30));
                string ignored;
                new SubQueueStrategy().TryMoveMessage(endPointsQueue, peek, SubQueue.Endpoints, out ignored);
            }

            using (var loadBalancer = container.Resolve <MsmqLoadBalancer>())
            {
                loadBalancer.Start();

                Assert.True(loadBalancer.KnownEndpoints.GetValues().Contains(TestQueueUri.Uri));
            }
        }
Пример #24
0
        public void Error_subqeueue_will_contain_error_details()
        {
            using (var bus = container.Resolve <IStartableServiceBus>())
            {
                bus.Start();

                queue.Send(new Message
                {
                    AppSpecific = (int)MessageType.AdministrativeMessageMarker,
                    Body        = "as",
                    Label       = "foo"
                });

                using (var q = MsmqUtil.GetQueuePath(bus.Endpoint).Open())
                    using (var errorSubQueue = q.OpenSubQueue(SubQueue.Errors, QueueAccessMode.SendAndReceive))
                    {
                        var originalMessage   = errorSubQueue.Receive();
                        var errorDescripotion = errorSubQueue.Receive();
                        Assert.Equal("Error description for: " + originalMessage.Label, errorDescripotion.Label);
                    }
            }
        }
Пример #25
0
        protected void SendToQueue(Uri queueUri, params object[] msgs)
        {
            if (queueUri == null)
            {
                return;
            }

            try
            {
                var queueInfo = MsmqUtil.GetQueuePath(new Endpoint {
                    Uri = queueUri
                });
                using (var secondaryLoadBalancerQueue = queueInfo.Open(QueueAccessMode.Send))
                {
                    secondaryLoadBalancerQueue.Send(GenerateMsmqMessageFromMessageBatch(msgs));
                }
            }
            catch (Exception e)
            {
                throw new LoadBalancerException("Could not send message to queue: " + queueUri, e);
            }
        }
Пример #26
0
        public void Execute(string user)
        {
            // will create the queues if they are not already there
            messageLoggingModule.Init(transport, null);
            var queuePath = MsmqUtil.GetQueuePath(new Endpoint
            {
                Uri = messageLoggingModule.LogQueue
            }).QueuePath;

            using (var queue = new MessageQueue(queuePath))
            {
                queue.SetPermissions(user,
                                     MessageQueueAccessRights.DeleteMessage |
                                     MessageQueueAccessRights.DeleteJournalMessage |
                                     MessageQueueAccessRights.GenericRead |
                                     MessageQueueAccessRights.GenericWrite |
                                     MessageQueueAccessRights.GetQueuePermissions |
                                     MessageQueueAccessRights.PeekMessage |
                                     MessageQueueAccessRights.ReceiveJournalMessage |
                                     MessageQueueAccessRights.ReceiveMessage |
                                     MessageQueueAccessRights.WriteMessage,
                                     AccessControlEntryType.Allow);
            }
        }
Пример #27
0
        public MsmqTestBase()
        {
            TestQueueUri  = new Uri("msmq://localhost/test_queue").ToEndpoint();
            testQueuePath = MsmqUtil.GetQueuePath(TestQueueUri).QueuePath;

            TestQueueUri2  = new Uri("msmq://localhost/test_queue2").ToEndpoint();
            testQueuePath2 = MsmqUtil.GetQueuePath(TestQueueUri2).QueuePath;

            TransactionalTestQueueUri  = new Uri("msmq://localhost/transactional_test_queue").ToEndpoint();
            transactionalTestQueuePath = MsmqUtil.GetQueuePath(TransactionalTestQueueUri).QueuePath;

            SubscriptionsUri2       = new Uri("msmq://localhost/test_queue2;subscriptions").ToEndpoint();
            subbscriptionQueuePath2 = MsmqUtil.GetQueuePath(SubscriptionsUri2).QueuePathWithSubQueue;

            SubscriptionsUri      = new Uri("msmq://localhost/test_queue;subscriptions").ToEndpoint();
            subscriptionQueuePath = MsmqUtil.GetQueuePath(SubscriptionsUri).QueuePathWithSubQueue;

            if (MessageQueue.Exists(testQueuePath) == false)
            {
                MessageQueue.Create(testQueuePath);
            }

            if (MessageQueue.Exists(testQueuePath2) == false)
            {
                MessageQueue.Create(testQueuePath2);
            }

            if (MessageQueue.Exists(transactionalTestQueuePath) == false)
            {
                MessageQueue.Create(transactionalTestQueuePath, true);
            }

            queue = new MessageQueue(testQueuePath);
            queue.Purge();

            using (var errQueue = new MessageQueue(testQueuePath + ";errors"))
            {
                errQueue.Purge();
            }

            testQueue2 = new MessageQueue(testQueuePath2);
            testQueue2.Purge();

            using (var errQueue2 = new MessageQueue(testQueuePath2 + ";errors"))
            {
                errQueue2.Purge();
            }

            transactionalQueue = new MessageQueue(transactionalTestQueuePath);
            transactionalQueue.Purge();

            using (var errQueue3 = new MessageQueue(transactionalTestQueuePath + ";errors"))
            {
                errQueue3.Purge();
            }

            using (var discardedQueue = new MessageQueue(testQueuePath + ";discarded"))
            {
                discardedQueue.Purge();
            }

            using (var timeoutQueue = new MessageQueue(testQueuePath + ";timeout"))
            {
                timeoutQueue.Purge();
            }

            subscriptions = new MessageQueue(subscriptionQueuePath)
            {
                Formatter = new XmlMessageFormatter(new[] { typeof(string) })
            };
            subscriptions.Purge();

            using (var subscriptions2 = new MessageQueue(subbscriptionQueuePath2))
            {
                subscriptions2.Purge();
            }
        }
Пример #28
0
        public void When_Primary_loadBalacer_recieve_endPoints_it_sends_them_to_secondary_loadBalancer()
        {
            using (var loadBalancer = container.Resolve <MsmqLoadBalancer>())
            {
                var wait        = new ManualResetEvent(false);
                int timesCalled = 0;
                loadBalancer.SentNewEndpointPersisted += () =>
                {
                    timesCalled += 1;
                    if (timesCalled == 2)
                    {
                        wait.Set();
                    }
                };

                loadBalancer.Start();


                using (var loadBalancerMsmqQueue = MsmqUtil.GetQueuePath(loadBalancer.Endpoint).Open(QueueAccessMode.SendAndReceive))
                {
                    var queuePath = MsmqUtil.GetQueuePath(TestQueueUri2);
                    loadBalancerMsmqQueue.Send(new Message
                    {
                        ResponseQueue = queuePath.Open().ToResponseQueue(),
                        Body          = "a"
                    });

                    loadBalancerMsmqQueue.Send(new Message
                    {
                        ResponseQueue = queuePath.Open().ToResponseQueue(),
                        Body          = "a"
                    });

                    queuePath = MsmqUtil.GetQueuePath(TransactionalTestQueueUri);
                    loadBalancerMsmqQueue.Send(new Message
                    {
                        ResponseQueue = queuePath.Open().ToResponseQueue(),
                        Body          = "a"
                    });
                }


                wait.WaitOne(TimeSpan.FromSeconds(30), false);

                var messageSerializer = container.Resolve <IMessageSerializer>();

                using (var workers = new MessageQueue(testQueuePath2, QueueAccessMode.SendAndReceive))
                {
                    int work1 = 0;
                    int work2 = 0;

                    foreach (Message msg in workers.GetAllMessages())
                    {
                        object msgFromQueue = messageSerializer.Deserialize(msg.BodyStream)[0];

                        var newEndpointPersisted = msgFromQueue as NewEndpointPersisted;
                        if (newEndpointPersisted == null)
                        {
                            continue;
                        }

                        var endpoint = newEndpointPersisted.PersistedEndpoint;
                        if (endpoint == TestQueueUri2.Uri)
                        {
                            work1 += 1;
                        }
                        else if (endpoint == TransactionalTestQueueUri.Uri)
                        {
                            work2 += 1;
                        }
                    }

                    Assert.Equal(work1, 1);
                    Assert.Equal(work2, 1);
                }
            }
        }
 public Is_fixed_for_SubQueueStrategy()
 {
     openedQueue = MsmqUtil.GetQueuePath(TestQueueUri).Open();
 }
 public Is_fixed_for_FlatQueueStrategy()
 {
     openedQueue = MsmqUtil.GetQueuePath(testQueueEndPoint).Open();
 }