7 Replies Latest reply on Feb 1, 2016 5:07 PM by Justin Bertram

    Wildfly 10 default ActiveMQ client cannot connect to server

    Vladyslav Baidak Newbie

      Hi all,

       

      I'm new to Java EE and I'm working on my JMS test application

      I'm using default messaging-activemq in standalone-full.xml

       

      Here is what I have in jndi.properties:

      java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
      java.naming.provider.url=http-remoting://centos:8080
      java.naming.security.principal=shell
      java.naming.security.credentials=123456
      jboss.naming.client.ejb.context=true
      java.naming.factory.url.pkgs=org.jboss.ejb.client.naming

       

      And here is how I call it:

      public static void main(String[] args) throws NamingException, IOException {

        Properties properties = new Properties();
        properties.load(new FileInputStream(new File("jndi.properties")));
        Context context = new InitialContext(properties);
        ConnectionFactory factory =

        (ConnectionFactory) context.lookup("jms/RemoteConnectionFactory");

        Destination topic = (Destination) context.lookup("jms/topic/ItemsTopic");

        Item item = new Item("PSV", "Sony PlayStation Vita", 4000);

        sendMessage(factory, topic, item);
      }

       

      private static void sendMessage(ConnectionFactory factory, Destination destination, Serializable message) {

        try (JMSContext jmsContext = factory.createContext()) {

        jmsContext.createProducer().send(destination, message);
        }

      }

       

      As a result I'm getting the following stacktrace:

      січ. 27, 2016 9:28:17 PM org.xnio.Xnio <clinit>

      INFO: XNIO version 3.3.1.Final

      січ. 27, 2016 9:28:17 PM org.xnio.nio.NioXnio <clinit>

      INFO: XNIO NIO Implementation Version 3.3.1.Final

      січ. 27, 2016 9:28:17 PM org.jboss.remoting3.EndpointImpl <clinit>

      INFO: JBoss Remoting version 4.0.9.Final

      січ. 27, 2016 9:28:19 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage

      INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]

      січ. 27, 2016 9:28:19 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate

      INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3a883ce7, receiver=Remoting connection EJB receiver [connection=Remoting connection <6d998ce2>,channel=jboss.ejb,nodename=localhost]} on channel Channel ID 8882c853 (outbound) of Remoting connection 6895a785 to centos/172.20.12.9:8080

      січ. 27, 2016 9:28:20 PM org.jboss.ejb.client.EJBClient <clinit>

      INFO: JBoss EJB Client version 2.1.3.Final

      Exception in thread "main" javax.jms.JMSRuntimeException: Failed to create session factory

        at org.apache.activemq.artemis.jms.client.JmsExceptionUtils.convertToRuntimeException(JmsExceptionUtils.java:88)

        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createContext(ActiveMQConnectionFactory.java:267)

        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createContext(ActiveMQConnectionFactory.java:253)

        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createContext(ActiveMQConnectionFactory.java:243)

        at com.software.shell.javaee.jms.item.ItemProducer.sendMessage(ItemProducer.java:36)

        at com.software.shell.javaee.jms.item.ItemProducer.main(ItemProducer.java:32)

        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:497)

        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

      Caused by: javax.jms.JMSException: Failed to create session factory

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

        at org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory.createContext(ActiveMQConnectionFactory.java:260)

        ... 9 more

      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:792)

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

        ... 10 more

       

      I searched in this error and found that there was an issue in ActiveMQhttps://issues.apache.org/jira/browse/ARTEMIS-290, but it seems it was fixed in Wildfly 7 EAP and I am using ver. 10

       

      Any ideas?

      Thanks!

        • 1. Re: Wildfly 10 default ActiveMQ client cannot connect to server
          Justin Bertram Master

          The JIRA issue ARTEMIS-290 has nothing to do with your issue as far as I can tell.  Furthermore, there is no such thing as "Wildfly 7 EAP."  But I digress...

           

          The error "AMQ119007: Cannot connect to server(s). Tried with all available servers." is common since it comes up just about anytime a client fails to connect to a server for any reason. 

           

          Can you provide more details about how you're starting Wildfly (e.g. what interface are you binding the server to)?

          • 2. Re: Wildfly 10 default ActiveMQ client cannot connect to server
            Vladyslav Baidak Newbie

            Sure

             

            I'm using the standalone-full.xml (renamed this file to standalone.xml) configuration and wildfly is running as a service

            netstat utility shows the following entries:

            tcp        0      0 0.0.0.0:3528            0.0.0.0:*              LISTEN      1175/java      

            tcp        0      0 0.0.0.0:3529            0.0.0.0:*              LISTEN      1175/java      

            tcp        0      0 0.0.0.0:8080            0.0.0.0:*              LISTEN      1175/java      

            tcp        0      0 0.0.0.0:9990            0.0.0.0:*              LISTEN      1175/java      

            tcp        0      0 127.0.0.1:47152        127.0.0.1:3306          ESTABLISHED 1175/java      

            tcp        0      0 127.0.0.1:47153        127.0.0.1:3306          ESTABLISHED 1175/java

            Any calls to java beans and jsf work fine on port 8080 and I use it to connect to actve-mq

             

            In standalone-full.xml I changed only interfaces block to:

                <interfaces>

                    <interface name="management">

                        <any-address/>

                    </interface>

                    <interface name="public">

                        <any-address/>

                    </interface>

                    <interface name="unsecure">

                        <any-address/>

                    </interface>

                </interfaces>

             

            Also, I created queue and topic for JMS:

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

                <jms-topic name="Items" entries="java:/jms/topic/ItemsTopic java:jboss/exported/jms/topic/ItemsTopic"/>

             

            The entire standalone-full.xml configuration attached (note that I renamed it to standalone.xml)

             

            Thanks for you help

            • 3. Re: Wildfly 10 default ActiveMQ client cannot connect to server
              Justin Bertram Master

              I think your issues would go away if you bound your server to a real IP address rather than 0.0.0.0.  However, if you have to bind to 0.0.0.0 then see this thread for more details on how to configure your connector(s) properly in that situation.

              • 4. Re: Wildfly 10 default ActiveMQ client cannot connect to server
                Vladyslav Baidak Newbie

                Hi Justin.

                Thanks for helping me.

                 

                I tried to start WildFly binding it to its real IP address (where it is hosted):

                ./standalone.sh -Djboss.bind.address=172.20.12.9

                This didn't help to connect.

                 

                Also I tried steps from the mentioned thread:

                1. Added another one interface:

                    <interfaces>

                          ...

                          <interface name="messaging-interface">

                              <inet-address value="172.20.12.9"/>

                          </interface>

                    </interfaces>

                2. Added socket-binding for it

                    <socket-binding name="messaging" port="8555" interface="messaging-interface"/>

                3. Configured messaging-activemq block to use them:

                    <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="messaging"/>

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

                                    <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="Items" entries="java:/jms/queue/ItemsQueue java:jboss/exported/jms/queue/ItemsQueue"/>

                              <jms-topic name="Items" entries="java:/jms/topic/ItemsTopic java:jboss/exported/jms/topic/ItemsTopic"/>

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

                              <connection-factory name="RemoteConnectionFactory" 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>

                 

                This also didn't help and moreover I do not see WilFly listening on port 8555, which is configured in socket-binding block for messaging

                I don't know may be the problem is within security, but it seems everything is working except jms

                • 5. Re: Wildfly 10 default ActiveMQ client cannot connect to server
                  Justin Bertram Master

                  I tried to start WildFly binding it to its real IP address (where it is hosted):

                  ./standalone.sh -Djboss.bind.address=172.20.12.9

                  This didn't help to connect.

                  Did you get the exact same error as before (i.e. "AMQ119007: Cannot connect to server(s). Tried with all available servers.")?

                   

                  This also didn't help and moreover I do not see WilFly listening on port 8555, which is configured in socket-binding block for messaging

                  The "http-acceptor" is a bit different from the traditional acceptor.  It is meant to piggy-back on an existing HTTP server (e.g. Undertow in Wildfly) so I wouldn't expect to actually open up its own port are listen.

                   

                  I don't know may be the problem is within security, but it seems everything is working except jms

                  I haven't seen anything up to this point to indicate a problem with security.  All the information you've provided thus far points to simply network connectivity/configuration issues.  Is there a specific reason you suspect a security problem?

                   

                  As always, the more details you can provide the more likely it is I'll be able to help.

                  • 6. Re: Wildfly 10 default ActiveMQ client cannot connect to server
                    Vladyslav Baidak Newbie

                    Thanks for your help

                     

                    Finally I managed to get it work

                     

                    So I changed the port from 8555 to 8080 in a designated messaging socket-binding (the default didn't work):

                         <socket-binding name="messaging" interface="messaging-interface" port="8080"/>

                     

                    After this I've got an Exception:

                         AMQ119031: Unable to validate user: null

                     

                    Then I added username and password when creating JMSContext:

                         JMSContext jmsContext = factory.createContext("shell", "123456")

                    And assign guest role to "shell" user

                     

                    And as a result it works!

                    • 7. Re: Wildfly 10 default ActiveMQ client cannot connect to server
                      Justin Bertram Master

                      The whole thing still doesn't make sense.  If your changed configuration works then I think it's likely either your configuration before was broken or that was some environmental issue preventing the connection.  Either way I'm glad you've got it working.