Sorry about the perhaps overly complex test case pasted below, i can
send you the files if you like.
It seems that when the primary restarts it does not send it's workers
and endpoints reroute messgaes from secondary queue to primary.

SendingBusToLoadBalancer.config
<castle>
  <facilities>
    <facility id="rhino.esb" >
      <bus threadCount="1"
           numberOfRetries="5"
           endpoint="msmq://localhost/test_queue"/>
      <messages>
        <add name="Rhino.ServiceBus.Tests"
             endpoint="msmq://localhost/test_queue.balancer"/>
      </messages>
    </facility>
  </facilities>
</castle>

ReceivingBusWithLoadBalancer.config

<castle>
  <facilities>
    <facility id="rhino.esb" >
      <bus threadCount="1"
           numberOfRetries="5"
           loadBalancerEndpoint="msmq://localhost/test_queue.balancer"
           endpoint="msmq://localhost/test_queue2"/>
      <messages>
        <add name="Rhino.ServiceBus.Tests"
             endpoint="msmq://localhost/test_queue2"/>
      </messages>
    </facility>
  </facilities>
</castle>

using System;
using System.Messaging;
using System.Threading;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.LoadBalancer;
using Rhino.ServiceBus.Msmq;
using Xunit;

namespace Rhino.ServiceBus.Tests.LoadBalancer
{
    public class
Full_test_of_load_balancer_and_failover_and_recovery :
LoadBalancingTestBase
    {
        private readonly IWindsorContainer container;
        private readonly IWindsorContainer restartedContainer;
        private readonly IWindsorContainer receivingBusContainer;

        protected const string loadBalancerQueue2 = "msmq://localhost/
test_queue.balancer2";
        protected readonly string loadBalancerQueuePath2 =
MsmqUtil.GetQueuePath(new
Uri(loadBalancerQueue2).ToEndpoint()).QueuePath;

        public Full_test_of_load_balancer_and_failover_and_recovery()
        {
            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
                    {
                        threadCount = 1,
                        endpoint = new Uri(loadBalancerQueue),
                        secondaryLoadBalancer = new
Uri(loadBalancerQueue2),
                                transactional = TransactionalOptions.FigureItOut
                                 }).LifeStyle.Transient ,
                Component.For<MsmqSecondaryLoadBalancer>()
                    .DependsOn(new
                    {
                        threadCount = 1,
                        endpoint = new Uri(loadBalancerQueue2),
                        primaryLoadBalancer = new
Uri(loadBalancerQueue),
                                                transactional = 
TransactionalOptions.FigureItOut
                    })
                );

            receivingBusContainer = new WindsorContainer(new
XmlInterpreter(@"LoadBalancer\ReceivingBusWithLoadBalancer.config"));
            receivingBusContainer.Kernel.AddFacility("rhino.esb", new
RhinoServiceBusFacility());
            receivingBusContainer.AddComponent<TestHandler>();

            restartedContainer = new WindsorContainer(new
XmlInterpreter(@"LoadBalancer\ReceivingBusWithLoadBalancer.config"));
            restartedContainer.Kernel.AddFacility("rhino.esb", new
RhinoServiceBusFacility());
            restartedContainer.Register(
                Component.For<MsmqLoadBalancer>()
                .DependsOn(new
                       {
                           threadCount = 1,
                           endpoint = new Uri(loadBalancerQueue),
                           secondaryLoadBalancer = new
Uri(loadBalancerQueue),
                           transactional =
TransactionalOptions.FigureItOut
                       }).LifeStyle.Transient);
        }

        [Fact]
        public void
Can_send_messages_to_worker_even_when_load_balancer_goes_does_then_up_again()
        {
            using (var bus =
container.Resolve<IStartableServiceBus>())
            using (var bus2 =
receivingBusContainer.Resolve<IStartableServiceBus>())
            {
                bus.Start();
                bus2.Start();
                using (var secondaryLoadBalancer =
container.Resolve<MsmqSecondaryLoadBalancer>())
                {
                    using (var loadBalancer =
container.Resolve<MsmqLoadBalancer>())
                    {
                        loadBalancer.Start();
                        TestHandler.ResetEvent = new
ManualResetEvent(false);
                        TestHandler.GotMessage = false;
                        bus.Send(new TestMessage());
 
TestHandler.ResetEvent.WaitOne(TimeSpan.FromSeconds(5), false);

                        var waitForTakeover = new
ManualResetEvent(false);
 
secondaryLoadBalancer.TimeoutForHeartBeatFromPrimary =
TimeSpan.FromMilliseconds(100);
 
secondaryLoadBalancer.TookOverAsActiveLoadBalancer += () =>
waitForTakeover.Set();
                        secondaryLoadBalancer.Start();
                        Thread.Sleep(TimeSpan.FromSeconds(1)); //wait
for end point query to complete.

 
Assert.True(waitForTakeover.WaitOne(TimeSpan.FromSeconds(10), false));
                    }

                    TestHandler.ResetEvent = new
ManualResetEvent(false);
                    TestHandler.GotMessage = false;
                    bus.Send(new TestMessage());
 
TestHandler.ResetEvent.WaitOne(TimeSpan.FromSeconds(30), false);
                    Assert.True(TestHandler.GotMessage);

                }
                //new container to more closely simulate load balancer
restart.
                using (var loadBalancer =
restartedContainer.Resolve<MsmqLoadBalancer>())
                {
                    var restarted = new ManualResetEvent(false);
                    loadBalancer.Started += () => restarted.Set();
                    loadBalancer.Start();
 
Assert.True(restarted.WaitOne(TimeSpan.FromSeconds(10), false));

                    TestHandler.ResetEvent = new
ManualResetEvent(false);
                    TestHandler.GotMessage = false;
                    bus.Send(new TestMessage());
 
TestHandler.ResetEvent.WaitOne(TimeSpan.FromSeconds(10), false);
                    Assert.True(TestHandler.GotMessage);
                }
            }
        }
    }
    public class TestMessage
    {

    }

    public class TestHandler : ConsumerOf<TestMessage>
    {
        public static bool GotMessage;
        public static ManualResetEvent ResetEvent;

        public void Consume(TestMessage message)
        {
            GotMessage = true;
            ResetEvent.Set();
        }
    }

}

On Mar 23, 8:07 pm, Ayende Rahien <[email protected]> wrote:
> No, that is not the expected behavior :-)
> It has been a while, but I think that we have a test for this.
> Can you try providing a test case for this?
> The primary should start responding to heartbeats and send its own re-route
> command.
>
> On Tue, Mar 23, 2010 at 6:29 PM, philip <[email protected]> wrote:
> > I have been experimenting with the RBS LoadBalancer functionality and
> > it broadly works as I would want, when the primary balancer goes down
> > the secondary balancer notices the heartbeat messages have stopped and
> > picks up the baton by sending ReRoute messages to interested parties
> > to receive new messages. The only problem I have found is that when
> > the PrimaryLoadBalancer restarts the secondaryloadbalancer won't give
> > up! in fact the only way to reactivate the primary is to restart the
> > sending and receiving buses which seems a little brutal.  Is this the
> > expected behaviour or have set it up incorrectly?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Rhino Tools Dev" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected]<rhino-tools-dev%[email protected]>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/rhino-tools-dev?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en.

Reply via email to