3 Replies Latest reply on Apr 5, 2019 7:24 AM by bhavesh.rkharwa

    Problems connecting from standalone client to ActiveMQ Queue (migrating from wildfly 9 to 10)

    tchoesang

      I am running a java standalone client (not running inside wildfly) which is connecting to a Widlfly JMS queue.

      The client was previously working with wildfly 9.0.2.FINAL and i am now trying to upgrade to wildfly 10.0.0.FINAL

       

      standalone-full.xml

      <subsystem xmlns="urn:jboss:domain:messaging-activemq:1.0">
                  <server name="default">
                      <journal file-size="102400"/>
                      <transaction scan-period="30000" timeout="600000"/>
                      <shared-store-master/>
                      <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>
                      <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>
                      <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="xrun" entries="java:/jms/xrunQueue java:jboss/exported/jms/xrunQueue"/>
                      <jms-topic name="xrun" entries="java:/jms/xrunTopic java:jboss/exported/jms/xrunTopic"/>
                      <jms-topic name="Jobs" entries="java:/jms/Jobs java:jboss/exported/jms/Jobs"/>
                      <connection-factory name="InVmConnectionFactory" consumer-window-size="0" entries="java:/ConnectionFactory" connectors="in-vm"/>
                      <connection-factory name="RemoteConnectionFactory" consumer-window-size="0" reconnect-attempts="-1" connection-ttl="-1" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector"/>
                      <pooled-connection-factory name="activemq-ra" transaction="xa" entries="java:/JmsXA java:jboss/DefaultJMSConnectionFactory" connectors="in-vm"/>
                  </server>
              </subsystem>
      

       

      Here is my JNDI properties

      java.naming.provider.url=tcp://wildfly:8111
      java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory
      java.naming.security.principal=JMS_USER
      java.naming.security.credentials=JMS_PASSWORD
      


      Client code that does a JNDI lookup

      String connectionFactoryString = System.getProperty("connection.factory", "jms/RemoteConnectionFactory");
      connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
      

       

      The JNDI lookup throws a NamingException and fails to connect to the JMS queue.

       

      I have tried changing the connectionFactoryString to "ConnectionFactory" as stated in the Artemis documentation Using JMS | ActiveMQ Artemis Documentation

      ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");

       

      Tried using both

      java.naming.provider.url=http-remoting://wildfly:8111

      java.naming.provider.url=tcp://wildfly:8111


      I dont get any ClassNotFoundExceptions like Problem Writing java based JMS Client for WildFly10

       

      Any ideas what could be wrong with my configuration?

        • 1. Re: Problems connecting from standalone client to ActiveMQ Queue (migrating from wildfly 9 to 10)
          jbertram

          You have a couple of choices here:

          1. Use the Artemis JNDI implementation which is different than the HornetQ JNDI implementation in that it is 100% client-side (i.e. no remote look-up is performed).
          2. Use the Wildfly JNDI implementation.

           

          Right now you're using a mix of both so it's not surprising that it wouldn't work.

           

          If you choose option #1 you'll need to configure your jndi.properties like so:

          java.naming.factory.initial=org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory

          connectionFactory.jms/RemoteConnectionFactory=tcp://wildfly:8111?httpUpgradeEnabled=true&consumerWindowSize=0&reconnectAttempts=-1&connectionTtl=-1

          queue.jms/xrunQueue=xrun

          topic.jms/xrunTopic=xrun

          topic.jms/Jobs=Jobs

          Then nothing in your code should need to change.  Note: in this scenario nothing is actually looked up on the server.  Everything is configured in the jndi.properties file.

           

          If you choose option #2 you'll need to configure your jndi.properties like so:

          java.naming.provider.url=http-remoting://wildfly:8111

          java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory

          java.naming.security.principal=JMS_USER 

          java.naming.security.credentials=JMS_PASSWORD 

          • 2. Re: Problems connecting from standalone client to ActiveMQ Queue (migrating from wildfly 9 to 10)
            jbertram

            One more thing...

             

            I see your "jms/RemoteConnectionFactory" connection factory has a connection-ttl of "-1."  I would highly discourage this as any network issues which cause the client to lose its connection to the broker or if the client stops without properly closing its connection (e.g. if it crashes or is poorly written) then resources on the broker will leak since it won't be able to detect the dead connections and close them.

            • 3. Re: Problems connecting from standalone client to ActiveMQ Queue (migrating from wildfly 9 to 10)
              bhavesh.rkharwa

              Successfully lookup connectionfactory as per above comment. Please find below code for create connection and connection factory.

                     

                        Hashtable<String, Object> properties = new Hashtable<>();

                         properties.put("connectionFactory.ConnectionFactory", "(tcp://localhost:8080)?httpUpgradeEnabled=true&retryInterval=3000&reconnectAttempts=-1&initialConnectAttempts=10&maxRetryInterval=3000&clientFailureCheckPeriod=1000");

                         properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.activemq.artemis.jndi.ActiveMQInitialContextFactory");

                         InitialContext jndiContext = new InitialContext(properties);

                        ConnectoryFactory connFactory = (ConnectionFactory) jndiContext.lookup(connectionFactory);

                        Connection connection = connFactory.createConnection(userName, password);

                        session = connection.createSession(true, javax.jms.Session.AUTO_ACKNOWLEDGE);

               

                         Hashtable<String, Object> properties = new Hashtable<>();

                         properties.put(Context.INITIAL_CONTEXT_FACTORY, factoryInitial);

                         InitialContext ctx = new InitialContext(properties);

                         destination = (Destination) ctx.lookup("dynamicQueues/TestQueue"); //I can't put queue name in jndi.properties

               

                        MessageProducer producer = session.createProducer(destination);

                        producer.send(message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, msgTTL);

                       if (session.getTransacted() && session.getAcknowledgeMode() == Session.SESSION_TRANSACTED) {

                          session.commit();

                      }

               

              When I execute the above code then it throws error saying that Queue "TestQueue" does not exists. I have tried with lookup queue with dynamicQueues/TestQueue and jms/TestQueue but in both cases I got same error

              Can you please let me know what is wrong with this code.

               

              Please find below wildfly activemq configuration

               

              <server name="default" persistence-enabled="true">

                              <cluster password="${jboss.messaging.cluster.password:CHANGE ME!!}"/>

                              <bindings-directory path="/opt/shared/messaging/live/bindings"/>

                              <journal-directory path="/opt/shared/messaging/live/journal"/>

                              <large-messages-directory path="/opt/shared/messaging/live/largemessages"/>

                              <paging-directory path="/opt/shared/messaging/live/paging"/>

                              <security-setting name="#">

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

                              </security-setting>

                              <address-setting name="#" dead-letter-address="jms.queue.DLQ" expiry-address="jms.queue.ExpiryQueue" redelivery-delay="60000" max-delivery-attempts="5" max-size-bytes="50485760" page-size-bytes="10485760" address-full-policy="PAGE" redistribution-delay="1000"/>

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

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

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

                              </http-connector>

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

                                  <param name="buffer-pooling" value="false"/>

                              </in-vm-connector>

                              <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>

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

                                  <param name="buffer-pooling" value="false"/>

                              </in-vm-acceptor>

                              <broadcast-group name="bg-group1" jgroups-cluster="activemq-cluster" connectors="http-connector"/>

                              <discovery-group name="dg-group1" jgroups-cluster="activemq-cluster"/>

                              <cluster-connection name="my-cluster" address="jms" connector-name="http-connector" discovery-group="dg-group1"/>

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

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

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

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

                              <connection-factory name="RemoteConnectionFactory" entries="java:jboss/exported/jms/RemoteConnectionFactory" connectors="http-connector" ha="true" block-on-acknowledge="true" reconnect-attempts="-1"/>

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

                          </server>