12 Replies Latest reply on Jun 24, 2013 1:14 AM by syvaidya

    Remote JMS connection with UnknownHostException

    bessen

      I have a JMS client that connects to JBoss AS 7.1.1.Final. The client provides connection properties to the remote server using IP address (not hosname). However, the server appears to return the hostname and since it is not on our DNS server, the client code returns with UnknownHostException. This problem does not happens with EJB remote lookup.

       

      If I'll add this server name myhost to the client HOSTS file it will work, but this is not acceptable by the costumers (to make changes to all clients). I have tried to run JBoss with -b <IP> option and it still did not help.

       

      is the a way to config JBoss AS 7 to work only with the IP address?

       

      Here is my sample code and the stack trace:

       

      public class MessageClient {

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

              final Context context = getInitialContext();

              QueueConnection conn = null;

              QueueSession session = null;

       

              try {

                  QueueConnectionFactory qcf = (QueueConnectionFactory)context.lookup("jms/RemoteConnectionFactory");

                  conn = qcf.createQueueConnection("jmsuser", "password");

                  conn.start();

                  Queue queue = (Queue)context.lookup("queue/test");

                  session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

       

                  System.out.println("Got qcf " + qcf);

                  System.out.println("Got q " + queue);

       

       

       

              } finally {

                  try {

                      conn.stop();

                  } catch (Exception ignore) {

                  }

                  try {

                      session.close();

                  } catch (Exception ignore) {

                  }

                  try {

                      conn.close();

                  } catch (Exception ignore) {

                  }

              }

          }

       

          public static Context getInitialContext( ) throws javax.naming.NamingException {

       

              Properties p = new Properties( );

              p.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());

              p.put(Context.PROVIDER_URL, "remote://x.x.x.x:4447");

              p.put("jboss.naming.client.ejb.context", true);

              return new javax.naming.InitialContext(p);

          }

      }

      stacktrace:

       

      SEVERE: Failed to create netty connection

      java.net.UnknownHostException: myhost

              at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)

              at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)

              at java.net.Socket.connect(Socket.java:529)

              at org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.connect(OioClientSocketPipelineSink.java:114)

              at org.jboss.netty.channel.socket.oio.OioClientSocketPipelineSink.eventSunk(OioClientSocketPipelineSink.java:74)

              at org.jboss.netty.channel.Channels.connect(Channels.java:541)

              at org.jboss.netty.channel.AbstractChannel.connect(AbstractChannel.java:210)

              at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:227)

              at org.jboss.netty.bootstrap.ClientBootstrap.connect(ClientBootstrap.java:188)

              at org.hornetq.core.remoting.impl.netty.NettyConnector.createConnection(NettyConnector.java:473)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnection(ClientSessionFactoryImpl.java:1143)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.getConnectionWithRetry(ClientSessionFactoryImpl.java:993)

              at org.hornetq.core.client.impl.ClientSessionFactoryImpl.connect(ClientSessionFactoryImpl.java:224)

              at org.hornetq.core.client.impl.ServerLocatorImpl.createSessionFactory(ServerLocatorImpl.java:747)

              at org.hornetq.jms.client.HornetQConnectionFactory.createConnectionInternal(HornetQConnectionFactory.java:601)

              at org.hornetq.jms.client.HornetQConnectionFactory.createQueueConnection(HornetQConnectionFactory.java:131)

              at com.client.MessageClient.main(MessageClient.java:34)

        • 1. Re: Remote JMS connection with UnknownHostException
          jbertram

          Can you attach your standalone*.xml?

          • 2. Re: Remote JMS connection with UnknownHostException
            bessen

            Here you go. I replaced the real IP with the loopback one. You can easily replicate the issue on a machine that does not register on the DNS.

            • 3. Re: Remote JMS connection with UnknownHostException
              robert.geisler

              any update on this??

               

              we currently see the same exception:

                   SEVERE: Failed to create netty connection

                   java.net.UnknownHostException: [HOSTNAME]

               

              i think the problem is that HornetQConnectionFactory uses hostname instead of ip address.
              because on the client side the hostname is not known, we get UnknownHostException.

               

              is there a way to configure messaging (or HornetQ) not to use hostname instead of ip?

               

              thanks in advance
              robert

              • 4. Re: Remote JMS connection with UnknownHostException
                jaysensharma

                Machine name is different than the actual  HostName which can be understood by the other odes reside on the same N/W.

                 

                which means If you have an entry with name "myhost" inside your "hosts" file (/etc/hosts)  then it does not mean that other machines will e able to cmmunicate with your machine with that name.

                 

                Are you able to do Telnet  from a remote machine to your JBoss liek following,(if not then you will need to make sure taht you bind your JBoss to a hostname/IPAddress which you can telnet from a remote machine):

                 

                 

                telnet   myhost   4447
                
                • 5. Re: Remote JMS connection with UnknownHostException
                  robert.geisler

                  well, correct me if i am wrong:

                   

                  i have

                  • a JMSConnetionFactory configured to use connector "netty".
                  • that connector is configured to use socket binding "message".
                  • that binding is defined to use interface with inet address [IP]

                  you see, that everthing is default config, just the property jboss.bind.address is being set via -D when starting JBoss.

                   

                  nevertheless on the client side i see that value "host" in HornetQConnectionFactory is [HOST]
                  (it is delivered by TransportConfiguration that i think is created on the JBoss server).
                  the client machine doesnt know who [HOST] is and throws an exception.

                   

                  that is why i like to use [IP] for the host parameter, so the client may connect successful.

                   

                  from my configuration i dont see any reason why ConnectionFactory uses hostname.
                  where is it configured??

                  • 6. Re: Remote JMS connection with UnknownHostException

                    We are also facing similar issue. Looks like HornetQ publishes the hostname to peers, and when peer tries to connect using that hostname, it fails because that hostname is not registered in DNS. We do not have option to add entry in /etc/hosts. Is there some way to fix this?

                    • 7. Re: Remote JMS connection with UnknownHostException
                      jbertram

                      After looking through the code related to this nothing jumps out at me which might be problematic.  Are you guys binding JBoss AS to 0.0.0.0 or a real IP address?

                       

                      Can you provide me with TRACE logging for "org.hornetq" from both the client and the server when this happens?  Unfortunately I haven't figure out a way to test this on my machine and I don't have access to a larger network.

                      • 8. Re: Remote JMS connection with UnknownHostException

                        We are binding to real IP address and not 0.0.0.0. This issue was in production, and so we forced the infra team to make the /etc/hosts entry, so it is working. Unfortunately I do not have another environment where I can reproduce this.

                         

                        Is there any way possible to configure hornetq to broadcast IP address of the server, and not the hostname?

                        • 9. Re: Remote JMS connection with UnknownHostException
                          jbertram

                          Is there any way possible to configure hornetq to broadcast IP address of the server, and not the hostname?

                          As far as I can tell from looking at the code it should be binding to the IP address and not the hostname. That's why I wanted to see logs.

                          • 10. Re: Remote JMS connection with UnknownHostException
                            jbertram

                            I believe I found the issue.  See https://issues.jboss.org/browse/AS7-4594.  This was fixed in AS 7.1.2 so if you're using 7.1.1 you should upgrade.

                            • 11. Re: Remote JMS connection with UnknownHostException
                              robert.geisler

                              hi justin!

                               

                              i cannot reproduce the problem anymore, too, because our DNS now knows the hostname of the machine that runs JBoss 7.
                              but here are some logs from JBoss 7:

                               

                              [DATE] INFO  [org.hornetq.core.remoting.impl.netty.NettyAcceptor] (MSC service thread 1-3) Started Netty Acceptor version 3.2.5.Final-a96d88c [HOSTNAME].[DOMAIN]:[MESSAGING-PORT] for CORE protocol

                              [DATE] INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) Server is now live

                              [DATE] INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-3) HornetQ Server version 2.2.13.Final (HQ_2_2_13_FINAL_AS7, 122) [36d4f499-c93d-11e2-b59a-902b3411ef3b]) started

                               

                              we use socket-binding-group "standard-sockets" with port-offset [OFFSET] and default-interface "public".
                              interface "public" uses default net-address value "${jboss.bind.address:127.0.0.1}" and we start JBoss 7 with -Djboss.bind.address=[IP].

                               

                              as shown in the logs not [IP] is used, but [HOSTNAME].[DOMAIN].

                              what are we doing wrong? : ) any ideas?

                               

                              EDIT: i was too late, sorry! thank you, Justin!

                               

                              thanks in advance!

                              regards

                              robert

                              • 12. Re: Remote JMS connection with UnknownHostException

                                Thanks Justin. We can't upgrade as of now, and so have forced the infra team to make /etc/hosts entries.