3 Replies Latest reply on Sep 2, 2011 10:34 AM by Frank Liu

    HornetQ Clustering

    michaelbini Newbie

      Hi,

      This is the first time that I am cluster so please be gentle with me

      I am clustering Jboss 5.1 with HornetQ. At the begining I add into the folder all-with-hornetq a queuq ($JBOSS_HOME\server\default-with-hornetq\deploy\hornetq.sar\hornetq-jms.xml).

      <queue name="PaymentsQueue">

            <entry name="/queue/PaymentsQueue"/>

      </queue>

       

      Then I copy the folder "all-with-hornetq" inot two folders(names: nodeA & nodeB) then I run this two commands :

      1.run.bat -c nodeA

      2.run.bat -c nodeB -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=2

      untill now every thig is ok running and no exception.

      now I write this simple jms consumer :

       


      public void onMessage(Message msg) {


      TextMessage tm = (TextMessage) msg;






      try {




      try {





      System.out.println("message receieved: " + tm.getText() +" "+ InetAddress.getLocalHost().toString());




      } catch (UnknownHostException e) {





      e.printStackTrace();




      }



      } catch (JMSException e) {




      e.printStackTrace();



      }

      }

       

      My problem is that only one server is receving the message.

      What I am doing wrong ?

        • 1. Re: HornetQ Clustering
          Frank Liu Newbie

          Hornetq does not have a traditional clustered queue. But can be configured to act similarily to one.

           

          What you can do is have client side load-balancing. Mean the hornetq client knows about the 2 servers and itself round robin the messages between the servers.

           

          Another way is to configure a cluster connection between the two servers. This where a Core Bridge is automatically configured for you to redistribute message between the servers with same name queues. This way a client can have knowledge of one server send all message to that server and the cluster core bridge would take message from it and forward to the second server.

           

          This is just for load balancing, HA and fail over has completely different configuration involved.

          1 of 1 people found this helpful
          • 2. Re: HornetQ Clustering
            michaelbini Newbie

            Thank's for your answer,

            can you explain more about the second method(A link about it will be fine)

            noe more question is how do i send message to this server :

            "run.bat -c nodeB -Djboss.service.binding.set=ports-01 -Djboss.messaging.ServerPeerID=2"

            I try this -

            ------------------

            Properties p = new Properties();

                                          p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");   

                                          p.put(Context.PROVIDER_URL, "localhost:2099");

                                          p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                                          context = new InitialContext(p);

            -----------------

            But still the first server is receving the message, am I doing something wrong ?



            • 3. Re: HornetQ Clustering
              Frank Liu Newbie

              First the -Djboss.messaging.ServerPeerID=2 is not used by hornetq, that was used in the original jboss messaging on 5.1. The server id configuration in hornetq is only used if you have multiple hornetq servers running in the same jvm or maybe machine, not sure which.

               

              Second the hornetq uses ipaddress to connect between servers(at least message broker does), that mean you cannot use bind address of 0.0.0.0 or localhost starting the jboss server. So if you configure the hornetq to start using the same jboss.bind.address and you start with 0.0.0.0 that wont work. You can either configure the hornetq bind address as a separate environment variable or change the jboss.bind.address to real ip address. Keep in mind localhost access will no longer work if you do the latter.

               

              http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/clusters.html#d0e10168

               

              This will help you with cluster connection for message redistribution with cluster.

               

              http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/clusters.html#clusters.message-redistribution

               

              Message redistribution with queues.

               

              http://docs.jboss.org/hornetq/2.2.5.Final/user-manual/en/html/clusters.html#d0e10395

               

              If you have low number of server you can manually specify the cluster servers yourself.

               

              I also recommend you download the source code to hornetq, they have examples configuration. You just need to combine static cluster example with message redistribution example and you're good to go.