6 Replies Latest reply on Dec 2, 2014 2:37 AM by Dimitar Yoldov

    HornetQ w/ REST webapp and JNDI ?

    Dimitar Yoldov Newbie

      Hi guys,

       

      I built the HornetQ w/ rest webapp as described in docs and managed to successfully run it with Jetty.

      I can connect without a problem using the jms client and core client, however I can't seem to be able to use JNDI.

       

      The built-in JNP JNDI server doesn't seem to be running on port 1099.

      Can anyone point me to some docs regarding using HornetQ+REST as well as JNDI?

      Is the built in naming server even running in my case?

       

      Any tips would be appreciated.

      Thanks in advance.

        • 1. Re: HornetQ w/ REST webapp and JNDI ?
          Justin Bertram Master

          How are you configuring and starting the HornetQ server?

          • 2. Re: Re: HornetQ w/ REST webapp and JNDI ?
            Dimitar Yoldov Newbie

            I am deploying it as a web application , with the HornetQ rest bootstrap listener and resteasy listener in the web.xml :

             

             

            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns="http://java.sun.com/xml/ns/javaee"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                                           http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
                       version="2.5">
                <listener>
                    <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
                </listener>
            
                <listener>
                    <listener-class>org.hornetq.rest.integration.HornetqBootstrapListener</listener-class>
                </listener>
            
                <listener>
                    <listener-class>org.hornetq.rest.integration.RestMessagingBootstrapListener</listener-class>
                </listener>
                
                <context-param>
                    <param-name>rest.messaging.config.file</param-name>
                    <param-value>/hornetq-example.xml</param-value>
                </context-param>
            
                <filter>
                    <filter-name>Rest-Messaging</filter-name>
                    <filter-class>
                        org.jboss.resteasy.plugins.server.servlet.FilterDispatcher
                    </filter-class>
                </filter>
            
                <filter-mapping>
                    <filter-name>Rest-Messaging</filter-name>
                    <url-pattern>/*</url-pattern>
                </filter-mapping>
            </web-app>
            

             

             

            I've got the configuration files (hornetq-beans.xml, hornetq-example.xml and hornetq-jms.xml) inside the classes folder of the webapp.

            Upon startup, the log shows that the queues are being created which leads me to believe the configuration files are being read.

            Here's a log:

             

            2014-11-25 15:57:17,479 - 2014-11-25 15:57:17.479:INFO:oejr.Runner:main: Runner
            2014-11-25 15:57:17,635 - 2014-11-25 15:57:17.635:INFO:oejs.Server:main: jetty-9.0.0.v20130308
            2014-11-25 15:57:18,992 - 2014-11-25 15:57:18.992:INFO:oejpw.PlusConfiguration:main: No Transaction manager found - if your webapp requires one, please configure one.
            2014-11-25 15:57:22,908 - Nov 25, 2014 3:57:22 PM org.hornetq.core.deployers.impl.FileConfigurationParser parseMainConfig
            2014-11-25 15:57:22,908 - WARN: HQ222018: AIO was not located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal
            2014-11-25 15:57:23,142 - Nov 25, 2014 3:57:23 PM org.hornetq.core.server.impl.HornetQServerImpl start
            2014-11-25 15:57:23,142 - INFO: HQ221000: live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=../data/journal,bindingsDirectory=../data/bindings,largeMessagesDirectory=../data/large-messages,pagingDirectory=../data/paging)
            2014-11-25 15:57:23,142 - Nov 25, 2014 3:57:23 PM org.hornetq.core.server.impl.HornetQServerImpl$SharedStoreLiveActivation run
            2014-11-25 15:57:23,142 - INFO: HQ221006: Waiting to obtain live lock
            2014-11-25 15:57:23,173 - Nov 25, 2014 3:57:23 PM org.hornetq.core.persistence.impl.journal.JournalStorageManager <init>
            2014-11-25 15:57:23,173 - INFO: HQ221013: Using NIO Journal
            2014-11-25 15:57:23,345 - Nov 25, 2014 3:57:23 PM org.hornetq.core.server.impl.HornetQServerImpl initialisePart1
            2014-11-25 15:57:23,345 - WARN: HQ222007: Security risk! HornetQ is running with the default cluster admin user and default password. Please see the HornetQ user guide, cluster chapter, for instructions on how to change this.
            2014-11-25 15:57:23,360 - Nov 25, 2014 3:57:23 PM org.hornetq.core.remoting.server.impl.RemotingServiceImpl <init>
            2014-11-25 15:57:23,360 - INFO: HQ221043: Adding protocol support CORE
            2014-11-25 15:57:23,502 - Nov 25, 2014 3:57:23 PM org.hornetq.core.server.impl.FileLockNodeManager startLiveNode
            2014-11-25 15:57:23,502 - INFO: HQ221034: Waiting to obtain live lock
            2014-11-25 15:57:23,502 - Nov 25, 2014 3:57:23 PM org.hornetq.core.server.impl.FileLockNodeManager startLiveNode
            2014-11-25 15:57:23,502 - INFO: HQ221035: Live Server Obtained live lock
            2014-11-25 15:57:25,202 - Nov 25, 2014 3:57:25 PM org.hornetq.core.server.impl.HornetQServerImpl deployQueue
            2014-11-25 15:57:25,202 - INFO: HQ221003: trying to deploy queue jms.queue.TVISION.EVENT.QUEUE
            2014-11-25 15:57:25,296 - Nov 25, 2014 3:57:25 PM org.hornetq.core.server.impl.HornetQServerImpl deployQueue
            2014-11-25 15:57:25,296 - INFO: HQ221003: trying to deploy queue jms.queue.TVISION.CONFIGURATION.QUEUE
            2014-11-25 15:57:25,670 - Nov 25, 2014 3:57:25 PM org.hornetq.core.remoting.impl.netty.NettyAcceptor start
            2014-11-25 15:57:25,670 - INFO: HQ221020: Started Netty Acceptor version 4.0.13.Final localhost:5445
            2014-11-25 15:57:25,701 - Nov 25, 2014 3:57:25 PM org.hornetq.core.remoting.impl.netty.NettyAcceptor start
            2014-11-25 15:57:25,701 - INFO: HQ221020: Started Netty Acceptor version 4.0.13.Final localhost:5455
            2014-11-25 15:57:25,795 - Nov 25, 2014 3:57:25 PM org.hornetq.core.server.impl.HornetQServerImpl$SharedStoreLiveActivation run
            2014-11-25 15:57:25,795 - INFO: HQ221007: Server is now live
            2014-11-25 15:57:25,795 - Nov 25, 2014 3:57:25 PM org.hornetq.core.server.impl.HornetQServerImpl start
            

             

            I can connect and put/get messages using the HornetQ client jar, but I cannot use JNDI

            • 3. Re: Re: HornetQ w/ REST webapp and JNDI ?
              Justin Bertram Master

              Take a look at org.hornetq.rest.integration.HornetQBootstrapListener and you'll see that the JNDI registry which is set uses the ServletContext for all the JNDI bindings which means you can do your "JNDI lookup" using the getAttribute method from the application's ServletContext.

              • 4. Re: Re: HornetQ w/ REST webapp and JNDI ?
                Dimitar Yoldov Newbie

                I understand what you mean.

                But what if I want to use a client external to the servlet container?

                 

                I'm running all of this under Jetty and I would like to connect an application in an external JVM through JMS+JNDI.

                Is this possible the way I have it configured, or should I reconfigure it somehow to allow that?

                • 5. Re: Re: HornetQ w/ REST webapp and JNDI ?
                  Justin Bertram Master

                  But what if I want to use a client external to the servlet container?

                  You could use either the core API or use the org.hornetq.api.jms.HornetQJMSClient to instantiate the JMS objects that you would normally look up via JNDI.

                   

                  I'm running all of this under Jetty and I would like to connect an application in an external JVM through JMS+JNDI.

                  I doesn't appear that is possible at this point.  You could modify the HornetQBootstrapListener to start a JNP server if you like, though.


                  Do you actually need the REST functionality that this configuration is meant to facilitate?  I haven't see you mention a requirement for REST in any of your previous comments.  If you don't need REST then I would recommend that you simply use HornetQ standalone rather than embedded within Jetty.  What specific purpose is Jetty serving in your environment?

                  • 6. Re: HornetQ w/ REST webapp and JNDI ?
                    Dimitar Yoldov Newbie

                    We're replacing SonicMQ with HornetQ and long story short - there are plenty of applications which require different ways of communication with the transport. One that uses JMS without JNDI, one that uses JMS+JNDI, one that posts using REST and a .NET application for which I'd need StompConnect from what I gather.

                     

                    I realize it's not a very common use case (to use nearly all of the available protocols) but it's necessary to this particular case, in order to minimize changes in all the applications.

                    Thanks for your input though, will try to modify the HornetQBootstrapListener


                    To answer your question - Jetty is used as a servlet container to host the webapp (HornetQ+RestEasy) , built as described in the docs.