2 Replies Latest reply on Mar 21, 2012 1:23 PM by anonymous401

    Connect Standalone HornetQ 2.2.5 and remote Sender-Client on JBoss 7.1.1 via JNDI

      Hi @ all!

       

      I am quite new to JBoss and HornetQ, but I am trying my best to connect a remote standalone HornetQ 2.2.5 with a Client running on JBoss 7.1.1.

      Later on, I will try listening on that queue with MDBs running on more JBoss 7.1.1 (in domain mode).

       

      I have already a standalone Client (not on JBoss) sending messages to the HornetQ, but I need the .jar files hornetq-core-client.jar, hornetq-jms-client.jar, jboss-jms-api.jar, jnp-client.jar, netty.jar and hornetq-transports.jar for this. And I don't want to use any other .jars than the ones in JBoss 7.1.1.

       

      My client:

       

      Context ctx = null;

                  Connection connection = null;

                  Session session = null;

                  try {

                        Hashtable<String, String> prop = new Hashtable<String, String>();

                        prop.put(Context.PROVIDER_URL, "jnp://remoteHost:1099");

                        prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");

                        prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

                        prop.put(Context.SECURITY_PRINCIPAL, "guest");

                        prop.put(Context.SECURITY_CREDENTIALS, "guestpw");

                        ctx = new InitialContext(prop);

                        ConnectionFactory cf = (ConnectionFactory) ctx.lookup("java:jboss/exported/jms/RemoteConnectionFactory");

                        Queue queue = (Queue) ctx.lookup("java:jboss/exported/jms/queue/testremotequeue");

                        connection = cf.createConnection("guest", "guestpw");

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

                        MessageProducer producer = session.createProducer(queue);

                        TextMessage message = session.createTextMessage();

                                           for (int i = 0; i < 100; i++) {

                              message.setText("This is message " + (i + 1));

                              System.out.println("Sending message: " + (i + 1));

                              producer.send(message);

                        }

                            }

      ...

       

      This code is not working when I deploy this client on a JBoss 7.1.1 and try to connect to the remote running HornetQ 2.2.5 and do not add any jars.

      The error-log I get:

      javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory]

            at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

            at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

            at javax.naming.InitialContext.init(Unknown Source)

            at javax.naming.InitialContext.<init>(Unknown Source)

            at beispiel.SenderClient.main(SenderClient.java:78)

      Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory

            at java.net.URLClassLoader$1.run(Unknown Source)

            at java.security.AccessController.doPrivileged(Native Method)

            at java.net.URLClassLoader.findClass(Unknown Source)

            at java.lang.ClassLoader.loadClass(Unknown Source)

            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

            at java.lang.ClassLoader.loadClass(Unknown Source)

            at java.lang.Class.forName0(Native Method)

            at java.lang.Class.forName(Unknown Source)

            at com.sun.naming.internal.VersionHelper12.loadClass(Unknown Source)

            ... 5 more

       

      I tried it with adding the jboss-client.jar, but I get the same error message.

       

      When I change the properties to:

      prop.put(Context.PROVIDER_URL, "remote://remoteHost:1099");

      prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

      prop.put(Context.URL_PKG_PREFIXES, "org.jboss.as.naming.interfaces");

       

      I get this error-log:

      21.03.2012 18:05:02 org.xnio.Xnio <clinit>

      INFO: XNIO Version 3.0.3.GA

      21.03.2012 18:05:02 org.xnio.nio.NioXnio <clinit>

      INFO: XNIO NIO Implementation Version 3.0.3.GA

      21.03.2012 18:05:02 org.jboss.remoting3.EndpointImpl <clinit>

      INFO: JBoss Remoting version 3.2.3.GA

      21.03.2012 18:05:02 org.jboss.remoting3.remote.RemoteConnection handleException

      ERROR: JBREM000200: Remote connection failed: java.io.IOException: Received an invalid message length of -1393754107

      javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: java.io.IOException: Received an invalid message length of -1393754107]

            at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)

            at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)

            at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)

            at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)

            at javax.naming.InitialContext.init(Unknown Source)

            at javax.naming.InitialContext.<init>(Unknown Source)

            at beispiel.SenderClient.main(SenderClient.java:78)

      Caused by: java.lang.RuntimeException: java.io.IOException: Received an invalid message length of -1393754107

            at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:87)

            at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)

            at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)

            at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)

            at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)

            ... 5 more

      ...

       

      I am quite desperate and didn't find anything on the web to help with exactly this problem (or I misunderstood).

       

      Can anybody help me and point me in the right direction? Is this even possible or are standalone HornetQ 2.2.5 and in JBoss 7.1.1 embedded HornetQ 2.2.13 incompatible?

       

      Thank you all for any hint!!!