8 Replies Latest reply on Jul 11, 2013 8:32 AM by erasmo2 marciano2

    How I can configure an failover on Jboss or Horneq?

    erasmo2 marciano2 Master

      HI

       

      I Have this client jms

       

      final int groupPort = 9876;

              try {

                  Queue queue = new HornetQQueue("testQueue");

                  Map<String, Object> connectionParams = new HashMap<String, Object>();

                  connectionParams.put(TransportConstants.CLUSTER_CONNECTION, "231.7.7.7:9876");    

                  //connectionParams.put(TransportConstants.PORT_PROP_NAME, 5445);

                  TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), connectionParams);

                //  ConnectionFactory cf = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.QUEUE_CF, transportConfiguration);    

                  ConnectionFactory cf = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithoutHA(new DiscoveryGroupConfiguration(groupAddress, groupPort), JMSFactoryType.QUEUE_CF);    

                  //JBoss requires passwords to have at least one numeric and non-alpha character

                  connection = cf.createConnection("admin","erasmo");

                  Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

                

                      MessageProducer producer = session.createProducer(queue);

                      connection.start();

                 

                  TextMessage message = session.createTextMessage("Howdy!");

                  //producer.send(message);

                

                 

                 

                  MessageConsumer consumer = session.createConsumer(queue);

                  //Message can also be consumed from here:

                  for (int i = 0; i < 1000; i++) { 

                     

                      message = (TextMessage) consumer.receive(3000);

                      LOGGER.info(message.getText());

                  }

       

      But when the messages end on node 1

       

      I get this message

       

      lug 11, 2013 9:39:34 AM org.jboss.as.quickstarts.jms.MyJMSClient main

      SEVERE: null


      But  the node 2 have other messages.

       

      If I run for second time my client I consume the messages in node2

       

      I'll probably have to confgiure a Failover but I don't Idea

       

      can I help me?

        • 1. Re: How I can configure an failover on Jboss or Horneq?
          Andy Taylor Master

          I would start by looking at the failover examples shipped with HornetQ and the HA section in the user manual, hint use HornetQJMSClient.createConnectionFactoryWithHA and configure a backup

          • 2. Re: How I can configure an failover on Jboss or Horneq?
            erasmo2 marciano2 Master

            Thank

            I tried but doesn't works

             

            I modified

               ConnectionFactory cf = (ConnectionFactory) HornetQJMSClient.createConnectionFactoryWithHA(new DiscoveryGroupConfiguration(groupAddress, groupPort), JMSFactoryType.QUEUE_CF);
                

             

             

            My configuration Jboss

             

            <subsystem xmlns="urn:jboss:domain:messaging:1.2">

                        <hornetq-server>

                            <clustered>true</clustered>

                            <persistence-enabled>true</persistence-enabled>

                            <security-enabled>false</security-enabled>

                            <cluster-user>admin</cluster-user>

                            <cluster-password>erasmo</cluster-password>

                        

                           <!-- When we shut down the live, we want failover to kick in. -->

                          <failover-on-shutdown>true</failover-on-shutdown>

             

             

            <discovery-groups>

                                <discovery-group name="my-discovery-group">

                                    <group-address>231.7.7.7</group-address>

                                    <group-port>9876</group-port>

                                    <refresh-timeout>10000</refresh-timeout>

                                </discovery-group>

                            </discovery-groups>

             

                            <cluster-connections>

                                <cluster-connection name="my-cluster">

                                    <address>jms</address>

                                    <connector-ref>netty</connector-ref>

                                    <retry-interval>500</retry-interval>

                                    <use-duplicate-detection>true</use-duplicate-detection>

                                    <forward-when-no-consumers>true</forward-when-no-consumers>

                                    <max-hops>1</max-hops>

                                    <discovery-group-ref discovery-group-name="my-discovery-group"/>

                                </cluster-connection>

                            </cluster-connections>

             

             

                        I do not have problems when sending messages

            • 4. Re: How I can configure an failover on Jboss or Horneq?
              erasmo2 marciano2 Master

              I tried with this file

               

               

              You will find attached

               

              CopyOfMyJMSClient2.java

               

              MyJMSClient.java

               

               

              Thank

               

              Have you an example?

               

               

              • 5. Re: How I can configure an failover on Jboss or Horneq?
                Andy Taylor Master

                there are many examples in the HornetQ distribution, try running these first. Also look at the user manual.

                • 6. Re: How I can configure an failover on Jboss or Horneq?
                  erasmo2 marciano2 Master

                  Hi there!

                   

                  What I would like is:

                   

                  - a custom JMS queue provider sending messages to a JBoss cluster (OK- I can send messages that are actually distributed round robin on my 2 nodes cluster)

                  - a custom JMS queue consumer as a webapp deployed on my 2 node JBoss cluster that should consume all queue messages sent by the provider at point 1;

                  - High Availability, so that if one of the JBoss nodes fails, the consumer can continue to get JMS queue messages

                   

                  I've checked the HorneQ code samples, and it seems that I can only make it working writing HA stuff by hand.

                  Is there a way for a JMS queue consumer deployed as a webapp into a JBoss cluster to get all JMS queue message in HA, so that if a jboss node fails I don't loose messages?

                  Thank you for your time.

                  • 7. Re: How I can configure an failover on Jboss or Horneq?
                    Andy Taylor Master

                    for High Availibilty you will need back up nodes, have you looked at the failover examples?

                    • 8. Re: How I can configure an failover on Jboss or Horneq?
                      erasmo2 marciano2 Master

                      Ok thanks.

                      So it seems that my consumer webapp will catch cluster nodes events which I have to react on (close and then open a new message session). Isn't it?

                      I'll try to implement this example: ClientSideFailoverListerExample

                       

                      Thank you.