3 Replies Latest reply on Apr 7, 2019 8:47 AM by hali19790320

    Wildfly 10.x connect to a remote HornetQ standalone server

    matafe

      I am migrating a application from JBoss AS 7 to Wildly 10.x but I am having some problems to setup. I read the Backward & Forward Compatibility Section but I have no success.

       

      Current I have an instance of AS7 connecting to a HornetQ standalone server:

       

      The client side: (AS7)

       

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

      ...

                  <hornetq-server>

      ...

                     <connectors>

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

                      </connectors>

                      <jms-connection-factories>

                          <pooled-connection-factory name="hornetq-ra">

                              <transaction mode="xa"/>

                              <user>dev</user>

                              <password>dev</password>

                              <min-pool-size>20</min-pool-size>

                              <max-pool-size>20</max-pool-size>

                              <connectors>

                                  <connector-ref connector-name="remote-jms"/>

                              </connectors>

                              <entries>

                                  <entry name="java:/MyConnectionFactory"/>

                              </entries>

                          </pooled-connection-factory>

                      </jms-connection-factories>

                 </hornetq-server>

              <outbound-socket-binding name="remote-jms-binding">

                  <remote-destination host="remotehornetqserverhost" port="5445"/>

              </outbound-socket-binding>

       

       

      How Can I configure the Wildfly 10.1.0 to connect to Remote HornetQ Standalone Server ?

       

      PS: All my JMS Queues are on server.

       

      Regards

        • 1. Re: Wildfly 10.x connect to a remote HornetQ standalone server
          matafe

          I think that I find out the solution:

           

          On the Wildfly 10.x:

           

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

                      <server name="default">

                          <connector name="remote-jms" factory-class="org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory">

                              <param name="host" value="localhost"/>

                              <param name="port" value="5445"/>

                          </connector>

                          <pooled-connection-factory name="hornetq-ra" transaction="xa" protocol-manager-factory="org.apache.activemq.artemis.core.protocol.hornetq.client.HornetQClientProtocolManagerFactory" entries="java:/RemoteHornetqConnectionFactory java:jboss/DefaultJMSConnectionFactory" connectors="remote-jms"/>

                      </server>

                  </subsystem>

           

          Notes:

          The Connection Factory on remote (in my case is localhost [port: 5445]) is named: RemoteHornetqConnectionFactory

           

          The DefaultJMSConnectionFactory is required to be here because the Java EE 7 Spec.

           

          Now you can the a Sender:

           

          Just a simple Example:

           

          @Stateless

          public class MessageSender {

           

            @Resource

            private ConnectionFactory connectionFactory;

           

            public void sendMessage(String text) {

           

            Connection connection = null;

            Session session = null;

           

            try {

            connection = connectionFactory.createConnection();

            connection.start();

           

            // Create a Session

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

           

            Queue queue = session.createQueue("testQueue");

           

            // Create a MessageProducer from the Session to the Topic or Queue

            MessageProducer producer = session.createProducer(queue);

           

            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

           

            // Create a message

            TextMessage message = session.createTextMessage(text);

           

            // Tell the producer to send the message

            producer.send(message);

           

            } catch (Exception e) {

            e.printStackTrace();

            } finally {

            // Clean up

            if (session != null)

            try {

            session.close();

            } catch (JMSException e) {

            e.printStackTrace();

            }

            if (connection != null)

            try {

            connection.close();

            } catch (JMSException e) {

            e.printStackTrace();

            }

            }

            }

           

           

            public String receiveMessage() {

           

            Connection connection = null;

            Session session = null;

            MessageConsumer consumer = null;

            try {

            connection = connectionFactory.createConnection();

            connection.start();

           

            // Create a Session

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

           

            Queue queue = session.createQueue("testQueue");

           

            // Create a MessageConsumer from the Session to the Topic or Queue

            consumer = session.createConsumer(queue);

           

            // Wait for a message

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

           

            return message == null ? null : message.getText();

            } catch (Exception e) {

            e.printStackTrace();

            } finally {

            if (consumer != null)

            try {

            consumer.close();

            } catch (JMSException e) {

            e.printStackTrace();

            }

            if (session != null)

            try {

            session.close();

            } catch (JMSException e) {

            e.printStackTrace();

            }

            if (connection != null)

            try {

            connection.close();

            } catch (JMSException e) {

            e.printStackTrace();

            }

            }

            return null;

            }

           

           

          }

           

          Regards.

          1 of 1 people found this helpful
          • 2. Re: Wildfly 10.x connect to a remote HornetQ standalone server
            m4maksud

            Worked fine for me! Thank you!

            • 3. Re: Wildfly 10.x connect to a remote HornetQ standalone server
              hali19790320

              Hi!

              Yes this worked, but just if hornetq is up to 2.3.0.CR1 and jboss 7.2 released with 2.3.0.CR1.

               

              How is possible the upgrade?

              Thanks.

              Halcsi