1 2 Previous Next 19 Replies Latest reply on Nov 15, 2012 10:51 AM by Johannes Hollerer

    Find Connection to HTTP Transport Servlet

    Johannes Hollerer Newbie

      Hi,

       

      I actually have an web application which uses HornetQ - embedded into the app.

      All the servlets are able to use that as a communication channel.

       

      Now i have one part of my application which serves on another server - in another network - with severl firewalls in between.

       

      Therefore i thought that the HTTPServlet solution would be a good idea - and i managed to reconfigure the server to use http transport - using the servlet.

       

      But how do i "find" that Endpoint - from another process on another machine - when only port 80 should be used (cannot use JNI for that) ?

      I also cannot find that in the examples - as there always the JNI or JMS service is used - but that is using other ports - and does not help there ?

       

      Can someone point me into the right direction....

       

      Thanks

        • 1. Re: Find Connection to HTTP Transport Servlet
          Yong Hao Gao Master

          Basically you need to config a connector that use servlet transport, for example:

           

           

          {code}

          <connector name="netty-servlet">

              <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>

              <param key="host" value="localhost"/>

              <param key="port" value="8080"/>

              <param key="use-servlet" value="true"/>

              <param key="servlet-path" value="/messaging/HornetQServlet"/>

          </connector>

          {code}

           

          and of course you need to deploy a hornetq servlet at the server. There are two servlet examples with HornetQ, (one of them use servlet with ssl), you may want to take a look.

           

          Howard

          • 2. Re: Find Connection to HTTP Transport Servlet
            Johannes Hollerer Newbie

            Hi Howard,

             

            Thanks  - for the answer, but i looked at the examples and they only take care about the server side.

            As mentioned i already setup the server - using the servlet, but i do not understand from client point of view how to connect to the "servlet" (and the server behind).

            The client cannot take the configuration, cannot take jms (port 80 only), cannot use jni (port 80 only) - and there is no example, to tell the client where to find the servlet (only using JNI which is not available).

             

            So what you described is the server part - which i fully understand - but my issue is to connect to that server now (only using port 80) !

             

            Thanks

            Johannes

            • 3. Re: Find Connection to HTTP Transport Servlet
              Andy Taylor Master

              simply configure another servlet connector with a different host or port.

              • 4. Re: Find Connection to HTTP Transport Servlet
                Andy Taylor Master

                this exactly what Howard explained, you just need to change the host and port to that of your remote server

                • 5. Re: Find Connection to HTTP Transport Servlet
                  Johannes Hollerer Newbie

                  So - to be clear:

                   

                  if i take the configuration for the server part to be

                   

                   

                  <connector name="netty-servlet">
                      <factory-class>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</factory-class>
                      <param key="host" value="myserver.com"/>
                      <param key="port" value="80"/>
                      <param key="use-servlet" value="true"/>
                      <param key="servlet-path" value="/messaging/HornetQServlet"/>
                  </connector>

                   

                  i then implement the client using:

                   

                  {code}

                  HashMap map = new HashMap();
                  map.put("host", "myserver.com");
                  map.put("port", 80);

                  map.put("use-servlet", "true");

                  map.put("servlet-path", "/messaging/HornetQServlet");
                  TransportConfiguration config = new TransportConfiguration(NettyConnectorFactory.class.getName(), map);
                  ClientSessionFactory sf = new ClientSessionFactoryImpl(config);

                  {code}

                   

                  right ?

                  • 6. Re: Find Connection to HTTP Transport Servlet
                    Andy Taylor Master

                    correct, however  if you are using core API you dont need to define the connector, if you are usingJMS API you define the conenctor and associate a connection factory with it.

                    1 of 1 people found this helpful
                    • 7. Re: Find Connection to HTTP Transport Servlet
                      Yong Hao Gao Master

                      If you can use jndi, look up the connection factory that is configured with a servlet connector.

                      • 8. Re: Find Connection to HTTP Transport Servlet
                        Johannes Hollerer Newbie

                        i tried the following:

                         

                         

                        {code}

                                    HashMap map = new HashMap();

                                    map.put("host", "localhost");

                                    map.put("port", 80);

                                    map.put("use-servlet", "true");

                                    map.put("servlet-path", "/messaging/HornetQServlet");

                                    TransportConfiguration config = new TransportConfiguration(NettyConnectorFactory.class.getName(), map);

                                    ServerLocator serverLocatorWithoutHA = HornetQClient.createServerLocatorWithoutHA(config);

                                    ClientSessionFactory sessionFactory = serverLocatorWithoutHA.createSessionFactory();

                        {code}

                         

                        but i get an exception:

                         

                        HornetQException[errorCode=3 message=Timed out waiting to receive cluster topology. Group:null]

                         

                        what do i need to change ?

                        • 9. Re: Find Connection to HTTP Transport Servlet
                          Yong Hao Gao Master

                          Please put full exception stack here (if any). Make sure your hornetq servlet is deployed correctly (i.e. the servlet's context root, mapping etc. should match '/messaging/HornetQServlet')

                          • 10. Re: Find Connection to HTTP Transport Servlet
                            Johannes Hollerer Newbie

                            There is not much more then that...

                            the rest goes back to my code - calling:  ClientSessionFactory sessionFactory = serverLocatorWithoutHA.createSessionFactory();

                             

                            {code}

                            HornetQException[errorCode=3 message=Timed out waiting to receive cluster topology. Group:null]

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

                            {code}

                             

                            i actually setup a test - with that code part - which starts in a servlet (deployed on a jetty server):

                             

                             

                            {code}

                            public void init() throws ServletException {

                                 try{

                                        EmbeddedJMS jms = new EmbeddedJMS();

                                        jms.start();

                             

                                        ConnectionFactory connectionFactory = (ConnectionFactory) jms.lookup("/ServletConnectionFactory");

                                        Queue queue = (Queue) jms.lookup("/queue/testQueue");

                                        Connection connection = connectionFactory.createConnection();

                             

                             

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

                                        MessageProducer messageProducer = connectionSession.createProducer(queue);

                                        TextMessage message = connectionSession.createTextMessage("This is a text message");

                                        messageProducer.send(message);

                                        MessageConsumer messageConsumer = connectionSession.createConsumer(queue);

                                        connection.start();

                                        TextMessage messageReceived = (TextMessage)messageConsumer.receive(5000);

                             

                                        System.out.println("Received message: " + messageReceived.getText());

                                    }catch (Exception e){

                                        e.printStackTrace();

                                        System.out.println(e);

                                    }

                            }

                            {code}

                             

                            still getting that error !

                            • 11. Re: Find Connection to HTTP Transport Servlet
                              Yong Hao Gao Master

                              There is nothing wrong with your client side code. I can run the code without any problem. I believe the problem is with your server.

                               

                              Can you upload your hornetq-configuration.xml and hornetq-jms.xml here?

                               

                              Just be aware that to be able to use servlet transport you need to deploy a 'special' servlet in the server. (see hornetq's servlet example). Once deployed, you should be able to view it from jmx-console.

                               

                              Howard

                              • 12. Re: Find Connection to HTTP Transport Servlet
                                Johannes Hollerer Newbie

                                Hi Howard,

                                 

                                Thanks for your help ....

                                 

                                thats my web.xml - starting the HttpTunnelingServlet - and then my HornetQ Servlet

                                {code}

                                    <servlet>

                                        <servlet-name>NettyServlet</servlet-name>

                                        <servlet-class>org.jboss.netty.channel.socket.http.HttpTunnelingServlet</servlet-class>

                                        <init-param>

                                            <param-name>endpoint</param-name>

                                            <param-value>local:localhost</param-value>

                                        </init-param>

                                        <load-on-startup>1</load-on-startup>

                                    </servlet>

                                 

                                 

                                    <servlet-mapping>

                                        <servlet-name>NettyServlet</servlet-name>

                                        <url-pattern>/HornetQServlet</url-pattern>

                                    </servlet-mapping>

                                 

                                 

                                    <servlet>

                                        <servlet-name>MessagingServer</servlet-name>

                                        <servlet-class>com.amergy.hornetqtest.MessagingServer</servlet-class>

                                        <load-on-startup>1</load-on-startup>

                                    </servlet>

                                 

                                {code}

                                 

                                find attached my configuration files

                                 

                                Thanks

                                Johannes

                                • 13. Re: Find Connection to HTTP Transport Servlet
                                  Yong Hao Gao Master

                                  Those seems fine. Only difference may be I'm using jboss 5 as container. Make sure your servlet also defines correct context root, like:

                                   

                                  <application>

                                    <display-name>My Application</display-name>

                                   

                                   

                                    <module>

                                      <web>

                                        <web-uri>servlet-transport-example.war</web-uri>

                                        <context-root>/messaging</context-root>

                                      </web>

                                    </module>

                                    

                                  </application>

                                   

                                  in my case. Also make sure your client use the correct port (in your server config the port is 8080), and also make sure your client uses hornetq client jars whose version matches the server's (esp netty jar should be the same between client and server).

                                   

                                  I upload my servlet ear here. Could you make it into your container and see if it works?

                                  • 14. Re: Find Connection to HTTP Transport Servlet
                                    Johannes Hollerer Newbie

                                    Hi Howard,

                                     

                                    Very strange - i checked again everything - and the servlet seems to be started (when i try to open the url http://localhost:8080/messaging/HornetQServlet) i see in the output

                                     

                                     

                                    {code}

                                    Nov 15, 2012 3:05:19 PM org.jboss.netty.channel.socket.http.HttpTunnelingServlet

                                    Warnung: Unallowed method: GET

                                    {code}

                                     

                                    so the hornetq servlet is there

                                    I also see the startup of the server ...

                                     

                                    {code}

                                    HornetQ Server version 2.2.19.SNAPSHOT (HQ_2_2_19_SNAPSHOT, 122) [6ed09b69-2d98-11e2-9cc1-a322d3524edd]) started

                                    {code}

                                     

                                     

                                    and still i get the error:

                                     

                                     

                                    {code}

                                    Caused by: HornetQException[errorCode=3 message=Timed out waiting to receive cluster topology. Group:null]

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

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

                                              ... 23 more

                                    {code}

                                     

                                    i am really stuck with it - i have no idea why this does not work out ...

                                    1 2 Previous Next