1 2 Previous Next 22 Replies Latest reply on Feb 27, 2013 3:40 AM by raymanf

    Creating JMS client producer sending to cluster.

    raymanf Newbie

      Hi,

      I am using HornetQ 2.1.1 integrated inside Spring3.1 (stand alone env)

       

      I have managed finally to configure my cluster mode(HA). I can confirm this when the backup server comes up it writes:

       

      Feb 25, 2013 9:20:07 AM org.hornetq.core.logging.impl.JULLogDelegate info
      INFO: backup announced
      

       

       

      I have created a client in order to test my env. my target is:

       

      Sending a message after taking down the master cluster node. And have the backup node to deal with the request without the client being noticed.

       

      When I used to work in jboss I could set a Partition Name/Discoverygroup so we dont need to set an exact target ip of a node in the client producder (for such cases).

       

      But now that I work in standalone env I have no idea how to do it.

       

      How should I modified my client and my cluster env code in order to send to Partition name/DiscoveryGroup and not an exact ip a jms message?

       

      so when 1 node being off the second one will take the request automaticlly (after all that is what my cluster about:) )

       

       

      My client produder code:

       

       

      Properties p = new Properties();
                                    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                                    p.put(Context.URL_PKG_PREFIXES, "jboss.naming:org.jnp.interfaces");
                                    p.put(Context.PROVIDER_URL, "localhost:1099");
                                    InitialContext context = new InitialContext(p);
                                    TopicConnectionFactory myConnFactory;
                                    Topic myTopic;
                                    System.out.println("connection factory lookup");
                                    myConnFactory = (javax.jms.TopicConnectionFactory) context.lookup("java:/ConnectionFactory");
                                    System.out.println("topic lookup");
                                    myTopic = (Topic) context.lookup("/topic/liquiditiyFeedTopic");
                                    topicConnection = myConnFactory.createTopicConnection();
                                    topicSession = topicConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                                      topicConnection.start();
      
                                                             
      

       

       

       

       

      thanks,

      ray.

        • 1. Re: Creating JMS client producer sending to cluster.
          raymanf Newbie

          I understood that I need to use DiscoveryGroupConfiguration.

          But cant find some example how to use it.

           

          any direction?

           

          thanks.

          • 2. Re: Creating JMS client producer sending to cluster.
            Yong Hao Gao Master

            I would suggest you take a look at some of HornetQ's cluster/failover examples, such as non-transactional-failover example.

            • 3. Re: Creating JMS client producer sending to cluster.
              raymanf Newbie

              Could you refer me to a link?

               

              thanks.

              • 4. Re: Creating JMS client producer sending to cluster.
                raymanf Newbie

                I am realy looking for a simple client example. but hard to find.

                 

                I am stuck within the DiscoveryGroupConfiguration part:

                 

                Connection connection = null;
                                    try
                                    {
                
                                              Topic topic = HornetQJMSClient.createTopic("liquiditiyFeedTopic");
                
                                              Map<String, Object> params = new HashMap<String, Object>();
                                              params.put(TransportConstants.PORT_PROP_NAME, 5445);
                                              params.put(TransportConstants.HOST_PROP_NAME, "localhost");
                                              TransportConfiguration config = new TransportConfiguration(
                                                                  "org.hornetq.core.remoting.impl.netty.NettyConnectorFactory", params);
                
                
                // no idea how to set it here?---
                
                                              DiscoveryGroupConfiguration dc=new DiscoveryGroupConfiguration(name, localBindAddress, groupAddress, groupPort, refreshTimeout, discoveryInitialWaitTimeout);
                
                
                // no idea how to set it here?---
                
                
                                              HornetQConnectionFactory jmsConnectionFactory = HornetQJMSClient.createConnectionFactoryWithHA(groupConfiguration, JMSFactoryType.CF);
                
                
                                  connection = jmsConnectionFactory.createConnection();
                
                
                                  session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                
                
                                  producer = session.createProducer(topic);
                
                
                                              // Step 7. Create a Text Message
                
                
                                              // Step 8. Send the Message
                
                
                TextMessage message = session.createTextMessage(msg);
                                    producer.send(message);
                
                

                 

                 

                 

                mybe you could assit?

                 

                thanks.

                • 5. Re: Creating JMS client producer sending to cluster.
                  Yong Hao Gao Master

                  You just need to go to download page http://www.jboss.org/hornetq/downloads and download the latest hornetq distribution, unzip it. All examples are included within the download.

                   

                  Howard

                  • 6. Re: Creating JMS client producer sending to cluster.
                    Andy Taylor Master

                    have a look at the examples like Howard said, also take a look at the javadocs for HornetQJMSClient

                    • 7. Re: Creating JMS client producer sending to cluster.
                      Yong Hao Gao Master

                      You probably need this API?  

                       

                      public static HornetQConnectionFactory createConnectionFactoryWithHA(final DiscoveryGroupConfiguration groupConfiguration, JMSFactoryType jmsFactoryType);

                       

                      It's in HornetQJMSClient class.

                       

                      Howard

                      • 8. Re: Creating JMS client producer sending to cluster.
                        raymanf Newbie

                        Yes.. already figured that out.. searching now in the examples to look for something similar..

                        • 9. Re: Creating JMS client producer sending to cluster.
                          raymanf Newbie

                          i was actully searching the whole examples couldnt find any mention to DiscoveryGroupConfiguration. mybe my whole direction is wrong? hope my question was clear.

                          • 10. Re: Creating JMS client producer sending to cluster.
                            raymanf Newbie

                            Hi,

                            Ok I have figure it out myself and it seems to work while the two nodes up.

                             

                            as soon as I kill the first node (to test the cluster) and then try to produce another message from the client I get that exception:

                             

                            javax.jms.IllegalStateException: Session is closed

                                      at org.hornetq.jms.client.HornetQSession.checkClosed(HornetQSession.java:1008)

                                      at org.hornetq.jms.client.HornetQSession.createTextMessage(HornetQSession.java:194)

                                      at SendMsgToTopicClient.sendMessageToTopic(SendMsgToTopicClient.java:143)

                                      at SendMsgToTopicClient.main(SendMsgToTopicClient.java:158)

                             

                             

                            thats my client code:

                             

                            Topic topic = HornetQJMSClient.createTopic("liquiditiyFeedTopic");
                                                          Map<String, Object> params = new HashMap<String, Object>();
                                                          params.put(TransportConstants.PORT_PROP_NAME, 5445);
                                                          params.put(TransportConstants.HOST_PROP_NAME, "localhost");
                            DiscoveryGroupConfiguration dc = new DiscoveryGroupConfiguration("231.7.7.7", 9876);
                                                          HornetQConnectionFactory jmsConnectionFactory = HornetQJMSClient.createConnectionFactoryWithHA(dc, JMSFactoryType.CF);
                                                          connection = jmsConnectionFactory.createConnection();
                                                          session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                            producer = session.createProducer(topic);
                            

                             

                            * I know the cluster works fine since the second node writes : INFO: backup announced"

                             

                            thanks.

                            • 11. Re: Creating JMS client producer sending to cluster.
                              Yong Hao Gao Master

                              Can you post the complete client code? Please note you should cache your producer for message sending. don't create a new connection/session/producer each time you send a message.

                               

                               

                              Howard

                              • 12. Re: Creating JMS client producer sending to cluster.
                                raymanf Newbie

                                I have attached the client code and in other hand the hornetq cluster server configurations of server1 and server2

                                • 13. Re: Creating JMS client producer sending to cluster.
                                  raymanf Newbie

                                  Those are the logs from server2:

                                   

                                  Feb 26, 2013 9:33:47 AM org.hornetq.core.logging.impl.JULLogDelegate info

                                  INFO: Waiting to become backup node

                                  Feb 26, 2013 9:33:47 AM org.hornetq.core.logging.impl.JULLogDelegate info

                                  INFO: ** got backup lock

                                  Feb 26, 2013 9:33:47 AM org.hornetq.core.logging.impl.JULLogDelegate info

                                  INFO: Using NIO Journal

                                  Feb 26, 2013 9:33:47 AM org.hornetq.core.logging.impl.JULLogDelegate warn

                                  WARNING: Security risk! It has been detected that the cluster admin user and password have not been changed from the installation default. Please see the HornetQ user guide, cluster chapter, for instructions on how to do this.

                                  Feb 26, 2013 9:33:47 AM org.hornetq.core.logging.impl.JULLogDelegate info

                                  INFO: HornetQ Backup Server version 2.2.14.Final (HQ_2_2_14_FINAL, 122) [67c8a76f-7e9b-11e2-9bdf-f5ead70f3c1e] started, waiting live to fail before it gets active

                                  Feb 26, 2013 9:33:48 AM org.hornetq.core.logging.impl.JULLogDelegate info

                                  INFO: backup announced

                                  • 14. Re: Creating JMS client producer sending to cluster.
                                    raymanf Newbie

                                    I was trying to look for this things in the docs. when the live server falling down does the backup server should write that it got active? coz it doesnt. the only thing I see on the backup startup is:

                                     

                                     

                                    INFO: backup announced

                                     

                                    Is there any other indication that the clusters nodes contacting each other completly?

                                     

                                    thanks.

                                    1 2 Previous Next