3 Replies Latest reply on Mar 24, 2011 4:35 AM by eivindsi

    How to embed HornetQ in Glassfish 3?

      What I tried to do was: deploying hornetq-ra.rar through glassfish admin console. Then I added Connector Connection Pool "hornetCF" for hornetq-ra.

       

      After that I try to send JMS message via:

       

        @Resource(mappedName="hornetCF")

        private QueueConnectionFactory testCF;

      It does not work. In the glassfish server log I see:

       

      [#|2010-01-31T21:58:24.396+0300|SEVERE|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=24;_ThreadName=Thread-1;|javax.jms.JMSException: Could not create a session: Error in allocating a connection. Cause: Error during setup

          at org.hornetq.ra.HornetQRASessionFactoryImpl.allocateConnection(HornetQRASessionFactoryImpl.java:881)

          at org.hornetq.ra.HornetQRASessionFactoryImpl.createQueueSession(HornetQRASessionFactoryImpl.java:237)

       

      It does not work even after launching standalone HornetQ at the same machine. Though my goal is to have HornetQ embedded, so it starts automatically together with glassfish.

       

      Sorry if this sounds crazy. I am sort of newby in this area. And googling did not help.

        • 1. Re: How to embed HornetQ in Glassfish 3?
          timfox

          The way a 3rd party JMS provider is integrated into a JEE app server depends on the specific app server.

           

          I don't know much about GF. The best place to ask would be the GF forums, since this will be GF config, not HornetQ config.

           

          I would expect GF has some documentation on how to do this somewhere.

          • 2. Re: How to embed HornetQ in Glassfish 3?

            Hi,

             

            Perhaps you could give me some guidance regaring HornetQ components. According to GF manual I need to:

             

            1. Deploy the generic resource adapter.

             

            OK. I have successfully deployed hornetq-ra.rar. Do I need to copy additional jars into server's classpath?

             

            2. Create a connector connection pool.

             

            Done this with default values and XA transaction support.

             

            3. Create a connector resource (which is JMS connection factory if I understand it right).

             

            Done this.

             

            4. Create an administered object resource (which is Queue or Topic).

             

            Here it fails:

            >asadmin create-admin-object

            Enter the value for the restype option> javax.jms.Queue

            Enter the value for the raname option> hornetq-ra

            Enter the value for the jndi_name operand> hornetqQ1

            com.sun.enterprise.admin.cli.CommandException: remote failure: Resource Adapter hornetq-ra does not

            contain any resource type for admin-object. Please specify another res-adapter.

            Command create-admin-object failed.

            If I try testing using just connector resource as connection factory and creating queue out of it dynamically, I get the following errors in the log:

             

            [#|2010-02-01T20:08:52.758+0300|WARNING|glassfishv3.0|javax.enterprise.resource.resourceadapter.com.sun.enterprise.connectors|_ThreadID=26;_ThreadName=Thread-1;|RAR5117 : Failed to obtain/create connection from connection pool [ hornetqpool ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Error during setup|#]

             

            [#|2010-02-01T20:08:52.760+0300|SEVERE|glassfishv3.0|org.hornetq.ra.HornetQRASessionFactoryImpl|_ThreadID=26;_ThreadName=Thread-1;|Could not create session

            javax.resource.spi.ResourceAllocationException: Error in allocating a connection. Cause: Error during setup

            at com.sun.enterprise.connectors.ConnectionManagerImpl.internalGetConnection(ConnectionManagerImpl.java:286)

            at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:217)

            at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:149)

            at com.sun.enterprise.connectors.ConnectionManagerImpl.allocateConnection(ConnectionManagerImpl.java:144)

            at org.hornetq.ra.HornetQRASessionFactoryImpl.allocateConnection(HornetQRASessionFactoryImpl.java:837)

            at org.hornetq.ra.HornetQRASessionFactoryImpl.createQueueSession(HornetQRASessionFactoryImpl.java:237)

            at ys.edel.booker.Test3Servlet.processRequest(Test3Servlet.java:101)

            at ys.edel.booker.Test3Servlet.doGet(Test3Servlet.java:32)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

            ...

            Caused by: com.sun.appserv.connectors.internal.api.PoolingException: Error during setup

            at com.sun.enterprise.resource.pool.datastructure.ListDataStructure.addResource(ListDataStructure.java:131)

            at com.sun.enterprise.resource.pool.ConnectionPool.addResource(ConnectionPool.java:268)

            ...

            Caused by: com.sun.appserv.connectors.internal.api.PoolingException: Error during setup

            at com.sun.enterprise.resource.pool.ConnectionPool.createSingleResource(ConnectionPool.java:842)

            at com.sun.enterprise.resource.pool.ConnectionPool.createResource(ConnectionPool.java:1087)

            at com.sun.enterprise.resource.pool.datastructure.ListDataStructure.addResource(ListDataStructure.java:121)

            ... 43 more

            |#]

             

            [#|2010-02-01T20:08:52.762+0300|SEVERE|glassfishv3.0|javax.enterprise.system.std.com.sun.enterprise.v3.services.impl|_ThreadID=26;_ThreadName=Thread-1;|javax.jms.JMSException: Could not create a session: Error in allocating a connection. Cause: Error during setup

            at org.hornetq.ra.HornetQRASessionFactoryImpl.allocateConnection(HornetQRASessionFactoryImpl.java:881)

            at org.hornetq.ra.HornetQRASessionFactoryImpl.createQueueSession(HornetQRASessionFactoryImpl.java:237)

            at ys.edel.booker.Test3Servlet.processRequest(Test3Servlet.java:101)

            at ys.edel.booker.Test3Servlet.doGet(Test3Servlet.java:32)

            at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)

            |#]

             

            Have I missed some important steps?

             

            And the main question: how to make HornetQ run embedded in the same JVM as glassfish?

            • 3. How to embed HornetQ in Glassfish 3?
              eivindsi

              I have also tried to make a HornetQ accessible from Glassfish apps. I have a standalone HornetQ, so I'm not trying to have is as an EMBEDDED JMS host in Glassfish.

               

              But I came across the same problem as you: "Resource Adapter hornetq-ra does not  contain any resource type for admin-object" when trying to add destination resources to Glassfish using the asadmin command:

               

              $ asadmin create-admin-object ...

               

              The reason this fails is that there is no <adminobject>...</adminobject> section in the ra.xml in hornetq-ra.rar.

               

              I've unzipped hornetq-ra.rar, added the <adminobject> section (see below) to ra.xml and zipped hornetq-ra.rar again:

               

              <connector>

              <resourceadapter>

                   ...

                   <adminobject>

                        <adminobject-interface>javax.jms.Queue</adminobject-interface>

                        <adminobject-class>org.hornetq.jms.client.HornetQQueue</adminobject-class>

                        <config-property>

                             <config-property-name>Name</config-property-name>

                             <config-property-type>java.lang.String</config-property-type>

                             <config-property-value></config-property-value>

                        </config-property>

                   </adminobject>

              </resourceadapter>

              </connector>

               

              and now the asadmin command succeds

               

              $ asadmin create-admin-object --restype javax.jms.Queue --raname hornetq-ra --property="Name=physical_queue_name" jndi_name

               

              The queue resources show up in the GF admin console, and looks so-far-so-good.

               

              To make this work I also had to add a no-argument constructor in  org.hornetq.jms.client.HornetQQueue in hornetq-ra.rar, and rebuild hornetq-ra.rar from source (which was no problem after downloading the source from the HornetQ web).

               

              But I'm not quite there yet. Now I struggle with using them in my apps. They use weld injection and the app fails when trying to send a JMS message through the HornetQ resource adapter, since the destination object sent to

               

              org.hornetq.jms.client.HornetQSession.createProducer(final Destination destination)

               

              is a org.jboss.weldx.jms.org...WeldProxy object, and createProducer won't accept that object type...