5 Replies Latest reply on Oct 3, 2012 3:49 PM by Justin Bertram

    JMS CLUSTER example HelloWorldJMSClient

    erasmo2 marciano2 Master

      HI

       

      I think I've made a correct configuration JMS CLUSTER with two JBOSS

       

      I have in output the following message:

       

      NODE A

       

      15:35:12,889 INFO  [org.hornetq.core.server.cluster.impl.BridgeImpl] (Thread-9 (HornetQ-server-HornetQServerImpl::serverUUID=aee80f1a-ff17-11e1-9bb7-31536c526998-17798304)) Bridge ClusterConnectionBridge@260657 [name=sf.my-cluster.b2778f9b-0d54-11e2-be2b-db8313d291f3, queue=QueueImpl[name=sf.my-cluster.b2778f9b-0d54-11e2-be2b-db8313d291f3, postOffice=PostOfficeImpl [server=HornetQServerImpl::serverUUID=aee80f1a-ff17-11e1-9bb7-31536c526998]]@6a4209 targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@260657 [name=sf.my-cluster.b2778f9b-0d54-11e2-be2b-db8313d291f3, queue=QueueImpl[name=sf.my-cluster.b2778f9b-0d54-11e2-be2b-db8313d291f3, postOffice=PostOfficeImpl [server=HornetQServerImpl::serverUUID=aee80f1a-ff17-11e1-9bb7-31536c526998]]@6a4209 targetConnector=ServerLocatorImpl [initialConnectors=[org-hornetq-core-remoting-impl-netty-NettyConnectorFactory?port=5446&host=localhost-localdomain], discoveryGroupConfiguration=null]]::ClusterConnectionImpl@4639333[nodeUUID=aee80f1a-ff17-11e1-9bb7-31536c526998, connector=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory?port=5445&host=localhost-localdomain, address=jms, server=HornetQServerImpl::serverUUID=aee80f1a-ff17-11e1-9bb7-31536c526998])) [initialConnectors=[org-hornetq-core-remoting-impl-netty-NettyConnectorFactory?port=5446&host=localhost-localdomain], discoveryGroupConfiguration=null]] is connected

       

      NODE B

       

      15:35:12,915 INFO  [org.hornetq.core.server.cluster.impl.BridgeImpl] (Thread-6 (HornetQ-server-HornetQServerImpl::serverUUID=b2778f9b-0d54-11e2-be2b-db8313d291f3-29237054)) Bridge ClusterConnectionBridge@17f6796 [name=sf.my-cluster.aee80f1a-ff17-11e1-9bb7-31536c526998, queue=QueueImpl[name=sf.my-cluster.aee80f1a-ff17-11e1-9bb7-31536c526998, postOffice=PostOfficeImpl [server=HornetQServerImpl::serverUUID=b2778f9b-0d54-11e2-be2b-db8313d291f3]]@169bc15 targetConnector=ServerLocatorImpl (identity=(Cluster-connection-bridge::ClusterConnectionBridge@17f6796 [name=sf.my-cluster.aee80f1a-ff17-11e1-9bb7-31536c526998, queue=QueueImpl[name=sf.my-cluster.aee80f1a-ff17-11e1-9bb7-31536c526998, postOffice=PostOfficeImpl [server=HornetQServerImpl::serverUUID=b2778f9b-0d54-11e2-be2b-db8313d291f3]]@169bc15 targetConnector=ServerLocatorImpl [initialConnectors=[org-hornetq-core-remoting-impl-netty-NettyConnectorFactory?port=5445&host=localhost-localdomain], discoveryGroupConfiguration=null]]::ClusterConnectionImpl@32983140[nodeUUID=b2778f9b-0d54-11e2-be2b-db8313d291f3, connector=org-hornetq-core-remoting-impl-netty-NettyConnectorFactory?port=5446&host=localhost-localdomain, address=jms, server=HornetQServerImpl::serverUUID=b2778f9b-0d54-11e2-be2b-db8313d291f3])) [initialConnectors=[org-hornetq-core-remoting-impl-netty-NettyConnectorFactory?port=5445&host=localhost-localdomain], discoveryGroupConfiguration=null]] is connected

       

      Now I'd like to test.

       

      I using the HelloWorldJMSClient but doesn't work.

       

        // Set up all the default values

          private static final String DEFAULT_MESSAGE = "Hello, World! ERASMOi CLUSTER JMS";

          private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";

          private static final String DEFAULT_DESTINATION = "jms/queue/test";

          //private static final String DEFAULT_DESTINATION = "jms/topic/test";

          private static final String DEFAULT_MESSAGE_COUNT = "10000";

          private static final String DEFAULT_USERNAME = "quickstartUser";

          private static final String DEFAULT_PASSWORD = "quickstartPassword";

          private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";

       

      //   private static final String PROVIDER_URL = "remote://127.0.0.1:4447";

       

      Can I use the my udp in this String?

       

          private static final String PROVIDER_URL = "remote://231.7.7.7:9876";

       

      .............

       

       

       

       

       

      Thank you

        • 1. Re: JMS CLUSTER example HelloWorldJMSClient
          Justin Bertram Master

          I using the HelloWorldJMSClient but doesn't work.

          What exactly doesn't work?

           

           

          Can I use the my udp in this String?

           

              private static final String PROVIDER_URL = "remote://231.7.7.7:9876";

          Port 9876 is not the JNDI lookup port so you can't use it for a JNDI lookup.  You should use 4447.

          1 of 1 people found this helpful
          • 2. Re: JMS CLUSTER example HelloWorldJMSClient
            erasmo2 marciano2 Master

            I'd like made an load-balancer JMS CLUSTER  How I can do this?

            • 3. Re: JMS CLUSTER example HelloWorldJMSClient
              Justin Bertram Master

              Check out chapter 38 in the HornetQ documentation.  Also, you can download HornetQ and look at the examples which deal with load-balancing (e.g. "client-side-load-balancing," "queue-message-redistribution," etc.).

              1 of 1 people found this helpful
              • 4. Re: JMS CLUSTER example HelloWorldJMSClient
                erasmo2 marciano2 Master

                Have you an exmple java jms ready for the load Balancig? or How I can modify this java code?

                <code>

                 

                /*

                * JBoss, Home of Professional Open Source

                * Copyright 2012, Red Hat, Inc. and/or its affiliates, and individual

                * contributors by the @authors tag. See the copyright.txt in the

                * distribution for a full listing of individual contributors.

                *

                * Licensed under the Apache License, Version 2.0 (the "License");

                * you may not use this file except in compliance with the License.

                * You may obtain a copy of the License at

                * http://www.apache.org/licenses/LICENSE-2.0

                * Unless required by applicable law or agreed to in writing, software

                * distributed under the License is distributed on an "AS IS" BASIS, 

                * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

                * See the License for the specific language governing permissions and

                * limitations under the License.

                */

                package org.jboss.as.quickstarts.jms;

                 

                 

                import java.util.logging.Logger;

                import java.util.Properties;

                 

                 

                import javax.jms.Connection;

                import javax.jms.ConnectionFactory;

                import javax.jms.Destination;

                import javax.jms.MessageConsumer;

                import javax.jms.MessageProducer;

                import javax.jms.Session;

                import javax.jms.TextMessage;

                import javax.naming.Context;

                import javax.naming.InitialContext;

                 

                 

                public class HelloWorldJMSClient {

                    private static final Logger log = Logger.getLogger(HelloWorldJMSClient.class.getName());

                 

                 

                    // Set up all the default values

                    private static final String DEFAULT_MESSAGE = "Hello, World!";

                    private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";

                    private static final String DEFAULT_DESTINATION = "jms/queue/test";

                    private static final String DEFAULT_MESSAGE_COUNT = "1";

                    private static final String DEFAULT_USERNAME = "quickstartUser";

                    private static final String DEFAULT_PASSWORD = "quickstartPassword";

                    private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";

                    private static final String PROVIDER_URL = "remote://localhost:4447";

                 

                 

                    public static void main(String[] args) throws Exception {

                 

                 

                        ConnectionFactory connectionFactory = null;

                        Connection connection = null;

                        Session session = null;

                        MessageProducer producer = null;

                        MessageConsumer consumer = null;

                        Destination destination = null;

                        TextMessage message = null;

                        Context context = null;

                 

                 

                        try {

                            // Set up the context for the JNDI lookup

                            final Properties env = new Properties();

                            env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);

                            env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));

                            env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", DEFAULT_USERNAME));

                            env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", DEFAULT_PASSWORD));

                            context = new InitialContext(env);

                 

                 

                            // Perform the JNDI lookups

                            String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);

                            log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");

                            connectionFactory = (ConnectionFactory) context.lookup(connectionFactoryString);

                            log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");

                 

                 

                            String destinationString = System.getProperty("destination", DEFAULT_DESTINATION);

                            log.info("Attempting to acquire destination \"" + destinationString + "\"");

                            destination = (Destination) context.lookup(destinationString);

                            log.info("Found destination \"" + destinationString + "\" in JNDI");

                 

                 

                            // Create the JMS connection, session, producer, and consumer

                            connection = connectionFactory.createConnection(System.getProperty("username", DEFAULT_USERNAME), System.getProperty("password", DEFAULT_PASSWORD));

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

                            producer = session.createProducer(destination);

                            consumer = session.createConsumer(destination);

                            connection.start();

                 

                 

                            int count = Integer.parseInt(System.getProperty("message.count", DEFAULT_MESSAGE_COUNT));

                            String content = System.getProperty("message.content", DEFAULT_MESSAGE);

                 

                 

                            log.info("Sending " + count + " messages with content: " + content);

                 

                 

                            // Send the specified number of messages

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

                                message = session.createTextMessage(content);

                                producer.send(message);

                            }

                 

                 

                            // Then receive the same number of messaes that were sent

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

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

                                log.info("Received message with content " + message.getText());

                            }

                        } catch (Exception e) {

                            log.severe(e.getMessage());

                            throw e;

                        } finally {

                            if (context != null) {

                                context.close();

                            }

                 

                 

                            // closing the connection takes care of the session, producer, and consumer

                            if (connection != null) {

                                connection.close();

                            }

                        }

                    }

                }

                 

                 

                 

                 

                </code>

                • 5. Re: JMS CLUSTER example HelloWorldJMSClient
                  Justin Bertram Master

                  Have you an exmple java jms ready for the load Balancig?

                  Yes.  As I said in my previous comment download HornetQ and look at the examples which deal with load-balancing (e.g. "client-side-load-balancing," "queue-message-redistribution," etc.).

                   

                  To be clear, load-balancing doesn't have anything to do with the JMS client code.  It's all about the configuration on the server-side.