5 Replies Latest reply on Nov 8, 2016 8:54 AM by jbertram

    Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues

    ramak517

      Hi,

       

      Could you please provide easy steps to migrate from jboss7.1 hornet jms queue's to wildfly10.0.0 Activemq queue's.

      I have tried below but couldn't work out.

       

      <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">

                  <server name="default">

                      <security-setting name="#">

                          <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>

                      </security-setting>

                      <address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>

                      <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>

                      <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">

                          <param name="batch-delay" value="50"/>

                      </http-connector>

                      <remote-connector name="netty" socket-binding="messaging"/>

                      <in-vm-connector name="in-vm" server-id="0"/>

                      <http-acceptor name="http-acceptor" http-listener="default"/>

                      <http-acceptor name="http-acceptor-throughput" http-listener="default">

                          <param name="batch-delay" value="50"/>

                          <param name="direct-deliver" value="false"/>

                      </http-acceptor>

                      <remote-acceptor name="netty" socket-binding="messaging"/>

                      <in-vm-acceptor name="in-vm" server-id="0"/>

                      <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>

                      <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>

                      <jms-queue name="TestSwiQ" entries="java:/jboss/exported/jms/queue/TestSwiQ"/>

                      <jms-queue name="ReceptionQueue" entries="java:/jboss/exported/jms/queue/ReceptionQueue"/>

                     

                      <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>

                      <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="netty"/>

                      <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>

                  </server>

              </subsystem>

       

       

      Java:

       

      import org.apache.activemq.artemis.api.core.TransportConfiguration;

      import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;

      import org.apache.activemq.artemis.api.jms.JMSFactoryType;

      import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;

       

      ........

       

      TransportConfiguration transportConfiguration = new TransportConfiguration(

        NettyConnectorFactory.class.getName());

       

       

        ConnectionFactory cf = ActiveMQJMSClient

        .createConnectionFactoryWithoutHA(JMSFactoryType.CF,

        transportConfiguration);

        Queue queue = ActiveMQJMSClient

        .createQueue(SWI_CONSTANTS.RECEPTION_QUEUE); // create the

        // connection

        connection = cf.createConnection();

        logger.info("create the connection"); // create the session session

        // =

        connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        logger.info("create the session");

        ObjectMessage message = session.createObjectMessage();

        message.setObject(response); //

        message.setJMSMessageID("Hello EJB3 MDB Queue!!!");

        logger.debug("1. Sent TextMessage to the Queue");

        MessageProducer sender = session.createProducer(queue);

        sender.send(message);

        logger.info("Message Sent");

       

       

       

      Regards,
      Rama.

        • 1. Re: Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues
          jbertram

          Could you be more specific about what "couldn't work out"?

          • 2. Re: Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues
            ramak517

            Hi Justin Bertram,

             

            I have create client to send messages to Queue "ReceptionQueue", and configuration subsystem added into standalone-full.xml.

            Please let me know do I have to add any other configuration?

            I see below exception:

             

            Caught: javax.jms.JMSException: Failed to create session factory

            javax.jms.JMSException: Failed to create session factory

            at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:727)

            at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:233)

            at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnection(ActiveMQConnectionFactory.java:229)

            at com.slb.swi.dct.utilities.MQTest.main(MQTest.java:27)

            Caused by: ActiveMQNotConnectedException[errorType=NOT_CONNECTED message=AMQ119007: Cannot connect to server(s). Tried with all available servers.]

            at org.apache.activemq.artemis.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:777)

            at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createConnectionInternal(ActiveMQConnectionFactory.java:724)

            ... 3 more

             

             

            Below is code and xml configuration.

             

            Java client:


            import javax.jms.Connection;
            import javax.jms.ConnectionFactory;
            import javax.jms.MessageProducer;
            import javax.jms.Queue;
            import javax.jms.Session;
            import javax.jms.TextMessage;

            import org.apache.activemq.artemis.api.core.TransportConfiguration;
            import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
            import org.apache.activemq.artemis.api.jms.JMSFactoryType;
            import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;

            public class MQTest {
            public static void main(String[] args) {
              try {

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

              ConnectionFactory cf = ActiveMQJMSClient
                .createConnectionFactoryWithoutHA(JMSFactoryType.CF,
                  transportConfiguration);
              Queue orderQueue = ActiveMQJMSClient
                .createQueue("jms/queue/ReceptionQueue");
              Connection connection = cf.createConnection();
              Session session = connection.createSession(false,
                Session.AUTO_ACKNOWLEDGE);
              MessageProducer producer = session.createProducer(orderQueue);
              connection.start();
              TextMessage message = session.createTextMessage("Sending Test Message");
              producer.send(message);
              session.close();
              connection.close();
              } catch (Exception e) {
              System.out.println("Caught: " + e);
              e.printStackTrace();
              }

            }
            }

             

            Standalone-full.xml:

             

            <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">

                        <server name="default">

                            <security-setting name="#">

                                <role name="guest" delete-non-durable-queue="true" create-non-durable-queue="true" consume="true" send="true"/>

                            </security-setting>

                            <address-setting name="#" message-counter-history-day-limit="10" page-size-bytes="2097152" max-size-bytes="10485760" expiry-address="jms.queue.ExpiryQueue" dead-letter-address="jms.queue.DLQ"/>

                            <http-connector name="http-connector" endpoint="http-acceptor" socket-binding="http"/>

                            <http-connector name="http-connector-throughput" endpoint="http-acceptor-throughput" socket-binding="http">

                                <param name="batch-delay" value="50"/>

                            </http-connector>

                            <remote-connector name="netty" socket-binding="messaging"/>

                            <in-vm-connector name="in-vm" server-id="0"/>

                            <http-acceptor name="http-acceptor" http-listener="default"/>

                            <http-acceptor name="http-acceptor-throughput" http-listener="default">

                                <param name="batch-delay" value="50"/>

                                <param name="direct-deliver" value="false"/>

                            </http-acceptor>

                            <remote-acceptor name="netty" socket-binding="messaging"/>

                            <in-vm-acceptor name="in-vm" server-id="0"/>

                            <jms-queue name="ExpiryQueue" entries="java:/jms/queue/ExpiryQueue"/>

                            <jms-queue name="DLQ" entries="java:/jms/queue/DLQ"/>

                            <jms-queue name="TestSwiQ" entries="java:/jboss/exported/jms/queue/TestSwiQ"/>

                            <jms-queue name="ReceptionQueue" entries="java:/jboss/exported/jms/queue/ReceptionQueue"/>

                            <connection-factory name="InVmConnectionFactory" entries="java:/ConnectionFactory" connectors="in-vm"/>

                            <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="netty"/>

                            <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>

                        </server>

                    </subsystem>

             

            With the same configuration could able to post messages to queue with below java client program, but not able to connect with netty configuration.

             

            import java.io.IOException;
            import java.util.Properties;

            //jms stuff
            import javax.jms.JMSException;
            import javax.jms.Queue;
            import javax.jms.QueueConnection;
            import javax.jms.QueueConnectionFactory;
            import javax.jms.QueueSender;
            import javax.jms.QueueSession;
            import javax.jms.Session;
            import javax.jms.TextMessage;
            import javax.naming.Context;
            import javax.naming.InitialContext;
            import javax.naming.NamingException;

            public class WildFlyJmsQueueSender {
              public final static String JMS_CONNECTION_FACTORY_JNDI="jms/RemoteConnectionFactory";
              public final static String JMS_QUEUE_JNDI="jms/queue/ReceptionQueue";
              public static String JMS_USERNAME="swiuser";       //  The role for this user is "guest" in ApplicationRealm
              public static String JMS_PASSWORD="swiuser123"; 
              public final static String WILDFLY_REMOTING_URL="http-remoting://localhost:8080";

              private QueueConnectionFactory qconFactory;
              private QueueConnection qcon;
              private QueueSession qsession;
              private QueueSender qsender;
              private Queue queue;
              private TextMessage msg;

              public static void main(String[] args) throws Exception {
                InitialContext ic = getInitialContext();
                WildFlyJmsQueueSender queueSender = new WildFlyJmsQueueSender();
                queueSender.init(ic, JMS_QUEUE_JNDI);
                readAndSend(queueSender);
                queueSender.close();
              }

              public void init(Context ctx, String queueName) throws NamingException, JMSException {
                qconFactory = (QueueConnectionFactory) ctx.lookup(JMS_CONNECTION_FACTORY_JNDI);
                
                //  If you won't pass jms credential here then you will get
                // [javax.jms.JMSSecurityException: HQ119031: Unable to validate user: null]   
                qcon = qconFactory.createQueueConnection(this.JMS_USERNAME, this.JMS_PASSWORD);  
                
                qsession = qcon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
                queue = (Queue) ctx.lookup(queueName);
                qsender = qsession.createSender(queue);
                msg = qsession.createTextMessage();
                qcon.start();
              }

              public void send(String message,int counter) throws JMSException {
                msg.setText(message);
                msg.setIntProperty("counter", counter);
                qsender.send(msg);
              }

              public void close() throws JMSException {
                qsender.close();
                qsession.close();
                qcon.close();
              }

              private static void readAndSend(WildFlyJmsQueueSender wildFlyJmsQueueSender) throws IOException, JMSException {
                String line="Test Message Body with counter = ";
                for(int i=0;i<10;i++) {
                      wildFlyJmsQueueSender.send(line+i,i);
                      System.out.println("JMS Message Sent: "+line+i+"\n");
                   }
              }

              private static InitialContext getInitialContext() throws NamingException {
                 InitialContext context=null;
                 try {
                       Properties props = new Properties();
                       props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
                       props.put(Context.PROVIDER_URL, WILDFLY_REMOTING_URL);   // NOTICE: "http-remoting" and port "8080"
                       props.put(Context.SECURITY_PRINCIPAL, JMS_USERNAME);
                       props.put(Context.SECURITY_CREDENTIALS, JMS_PASSWORD);
                       //props.put("jboss.naming.client.ejb.context", true);
                       context = new InitialContext(props);
                       System.out.println("\n\tGot initial Context: "+context);    
                  } catch (Exception e) {
                       e.printStackTrace();
                  }
                return context;
              }
            }

             

             

            Regards,
            Rama.

            • 3. Re: Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues
              jbertram

              TransportConfiguration transportConfiguration = new TransportConfiguration(

              NettyConnectorFactory.class.getName());

              ConnectionFactory cf = ActiveMQJMSClient
              .createConnectionFactoryWithoutHA(JMSFactoryType.CF,
              transportConfiguration);

              Here you're configuring a Netty connector with no host or port information which means the connector will default to localhost:61616.

               

              You've specified a "remote-acceptor" in your standalone-full.xml using the "messaging" socket binding, but you haven't included configuration details for the socket binding.  I assume it's either not listening on localhost or port 61616 or both.

              1 of 1 people found this helpful
              • 4. Re: Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues
                ramak517

                Hi Justin Bertram,

                 

                Thanks for your response.

                please find the attached standalone-full.xml, other than this I didn't configure any other xml's.

                Please let me know full configuration for "Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues" using netty configuration.

                 

                 

                If possible please refer useful link on Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues" using netty configuration.

                Regards,
                Rama.

                • 5. Re: Migrate jboss7.1 to wildfly10.0.0 - hornetQ jms to activemq jms Queues
                  jbertram

                  Assuming you're not binding Wildfly to an interface other than "localhost" or "127.0.0.1" then your problem is this:

                   

                  <socket-binding name="messaging" port="5445"/>
                  

                   

                  This should be 61616 rather than 5445 if you don't want to change your client.  Otherwise you should change your client to connect to port 5445 explicitly.