4 Replies Latest reply on May 27, 2014 10:21 AM by jbertram

    How to connect to a HornetQ server?

    cremersstijn

      I am trying to connect to a hornetq server from a groovy script:

       

      @Grapes([
        @Grab(group='org.hornetq', module='hornetq-commons', version='2.4.1.Final'),
        @Grab(group='jboss', module='jnp-client', version='4.2.2.GA'),
          @Grab(group='javax.jms', module='jms', version='1.1')
      ])
      
      
      import javax.naming.*
      import javax.jms.*
      
      
      
      
      String remoteUrl = "jnp://10.21.120.31:4747";
      Properties props = new Properties();
      props.put(Context.PROVIDER_URL, remoteUrl);
      props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      
      
      InitialContext ctx = new InitialContext(props);
      
      
      def connectionFactory = (QueueConnectionFactory) ctx.lookup("/ConnectionFactory")
      

       

       

      But i get the following error:

       

      Caught: javax.naming.CommunicationException: Could not obtain connection to any of these urls: 10.21.120.31:4747 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server 10.21.120.31:4747 [Root exception is java.io.StreamCorruptedException: invalid stream header: 00000013]]

      javax.naming.CommunicationException: Could not obtain connection to any of these urls: 10.21.120.31:4747 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server 10.21.120.31:4747 [Root exception is java.io.StreamCorruptedException: invalid stream header: 00000013]]

        at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1562)

        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:634)

        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:627)

        at SimpleJms.run(SimpleJms.groovy:19)

      Caused by: javax.naming.CommunicationException: Failed to retrieve stub from server 10.21.120.31:4747 [Root exception is java.io.StreamCorruptedException: invalid stream header: 00000013]

        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:268)

        at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1533)

        ... 3 more

      Caused by: java.io.StreamCorruptedException: invalid stream header: 00000013

        at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:255)

        ... 4 more

      [Finished in 7.1s with exit code 1]

       

       

      Any idea what i am doing wrong?

        • 1. Re: How to connect to a HornetQ server?
          jbertram

          Is HornetQ running standalone or in an application server (e.g. JBoss AS, WildFly, etc.)?

           

          The JNDI port you're using (i.e. 4747) is certainly non-standard.  I can't see any other potential problems aside from that given the information you've provided so far.

          • 2. Re: How to connect to a HornetQ server?
            cremersstijn

            I am running Hornet Q in eap 6.2. I have used port 4747 because i am running an port offset 300.

             

            This is my hortnet Q config:

             

            <connectors>
              <netty-connector name="netty" socket-binding="messaging"/>
              <netty-connector name="netty-throughput" socket-binding="messaging-throughput">
              <param key="batch-delay" value="50"/>
              </netty-connector>
              <in-vm-connector name="in-vm" server-id="0"/>
            </connectors>
            <acceptors>
              <netty-acceptor name="netty" socket-binding="messaging"/>
              <netty-acceptor name="netty-throughput" socket-binding="messaging-throughput">
              <param key="batch-delay" value="50"/>
              <param key="direct-deliver" value="false"/>
              </netty-acceptor>
              <in-vm-acceptor name="in-vm" server-id="0"/>
            </acceptors>


            <jms-connection-factories>
              <connection-factory name="myConnectionFactory">
              <connectors>
              <connector-ref connector-name="netty"/>
              </connectors>
              <entries>
              <entry name="/ConnectionFactory"/>
              </entries>
              </connection-factory>
            </jms-connection-factories>

            • 3. Re: How to connect to a HornetQ server?
              jmesnil

              Stijn Cremers wrote:

               

              I am trying to connect to a hornetq server from a groovy script:

               

              1. @Grapes([ 
              2.   @Grab(group='org.hornetq', module='hornetq-commons', version='2.4.1.Final'), 
              3.   @Grab(group='jboss', module='jnp-client', version='4.2.2.GA'), 
              4.     @Grab(group='javax.jms', module='jms', version='1.1'
              5. ]) 

               

               

              Any idea what i am doing wrong?

               

              EAP 6.2 is not using the jnp-client jar (that was used by previous version).

               

              If you are connecting to EAP 6.2 using JNDI and JMS, the best way is to use the BOM for jms-client (org.jboss.as:jboss-as-jms-client-bom) that is available in the EAP maven repository.

              • 4. Re: How to connect to a HornetQ server?
                jbertram

                I am running Hornet Q in eap 6.2...

                In that case your JNDI properties are all wrong.  Look here for an example of a standalone JMS client connecting to JBoss AS7/EAP 6.x.