5 Replies Latest reply on Sep 2, 2010 12:57 PM by whshub

    Sun glassfish app server intergation with hornetq

    jbossuser321

      My intention is to use a mdb on glassfish 3.0 to consume mesages from external hornetq jms broker. I followed the glassfish manual, and deployed hornetq-ra.rar, created connecter factory and resource. On the last step, I couldn't created the admin object resource.

       

      The error is: Resource Adapter hornetq-ra does not contain any resource type for admin-object. Please specify another res-adapter.

       

      I checked ra.xml in hornetq-ra.rar, no adminobject element exist. Doesn't hornetq ra support admin objects? If not, what can I do to integrate hornetq with sun glassfish app server?

        • 1. Re: Sun glassfish app server intergation with hornetq
          ataylor

          I'm not sure that this is the a question we can answer, I would try the Glassfish forum or there docs. To be honest I'm not even sure what an resource type 'admin-object' is.

          • 2. Re: Sun glassfish app server intergation with hornetq
            jbossuser321

            After going through sun's doc, I found a manual about how to config external connector. I was able to config the MDB to use the hornetq netty connection directly via physical name.  This worked for me. Thanks for the replies.

            • 3. Re: Sun glassfish app server intergation with hornetq
              clebert.suconic

              Can you share your steps?

               

              This would be a very intersting subject for a blog post.

              • 4. Re: Sun glassfish app server intergation with hornetq
                jbossuser321

                1. Deploy hornetq-rar.rar as a connector resource on glassfish admin console.


                2. Config sun-ejb-jar.xml

                ...
                        <mdb-resource-adapter>
                            <!-- The resource adapter mid element ties the generic ra for JMS
                            with this particular MDB -->
                            <resource-adapter-mid>hornetq-ra</resource-adapter-mid>
                            <activation-config>
                                <activation-config-property>
                                     <activation-config-property-name>destinationType</activation-config-property-name>
                                     <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
                                  </activation-config-property>
                                   <activation-config-property>
                                     <activation-config-property-name>destination</activation-config-property-name>
                                     <activation-config-property-value>physicalName</activation-config-property-value>
                                  </activation-config-property>
                                  <activation-config-property>
                                     <activation-config-property-name>ConnectorClassName</activation-config-property-name>
                                     <activation-config-property-value>org.hornetq.core.remoting.impl.netty.NettyConnectorFactory</activation-config-property-value>
                                  </activation-config-property>
                                  <activation-config-property>
                                     <activation-config-property-name>ConnectionParameters</activation-config-property-name>
                                     <activation-config-property-value>host=hornetq_server;port=5445</activation-config-property-value>
                                  </activation-config-property>
                                  <activation-config-property>
                                     <activation-config-property-name>UserName</activation-config-property-name>
                                     <activation-config-property-value>user</activation-config-property-value>
                                  </activation-config-property>
                                  <activation-config-property>
                                     <activation-config-property-name>Password</activation-config-property-name>
                                     <activation-config-property-value>pass</activation-config-property-value>
                                  </activation-config-property>
                                  </activation-config>           
                        </mdb-resource-adapter>

                 

                ....

                 

                3. Upload the jar files to glassfish classpath.

                netty.jar, hornetq-core-client-2.1.0.CR1.jar, hornetq-jms-client-2.1.0.CR1.jar, hornetq-logging-2.1.0.CR1.jar

                • 5. Re: Sun glassfish app server intergation with hornetq
                  whshub

                  I prefer minimizing the use xml files so here are my current setup steps.  This script works on my windows dev machine (via cygwin) using hornetq  2.1.1 and glassfish 3.0.1.

                   

                  Pending Issues:


                  * I still haven't figured out where the right place is to set the  username and password.  You'll see warnings in your Glassfish log to  this effect.  I'll edit this post when I correct that.

                  * Glassfish always complains (only seen if you have fine level logging on  for resource adapters) about the lack of methods getPassword and  getUserName and getUser. I'm also trying to figure out where this  problem comes from.  See an optional hack below the setup script that  makes these go away. I'm not currently using this hack but I confirmed  it worked with hq2.0/gf3.0.

                  * If you use glassfish redeploy (by touching .reload in your app  directory), you can no longer send/receive messages until you shutdown  and restart Glassfish.  Example errors are at the bottom of this thread
                  * UseXA=true is also in the wrong place.  Need to correct that location.

                  * Glassfish doesn't seem to correctly close connections with Hornetq  sometimes.  Example messages from Hornetq are below.

                   

                   

                   

                  Hornetq & Glassfish Setup Script

                   

                  # Copy support files to domain lib directory.  (Not sure why  these, except netty, aren't used already seen where they reside in the  ra application.)
                  cp netty.jar ${DOMAIN_DIR}/lib/
                  cp  hornetq-core-client.jar ${DOMAIN_DIR}/lib/
                  cp hornetq-jms-client.jar  ${DOMAIN_DIR}/lib/
                  cp hornetq-logging.jar ${DOMAIN_DIR}/lib/


                  # Start Domain
                  asadmin start-domain ${DOMAIN_NAME}


                  #  Deploy Resource adapter
                  asadmin deploy hornetq-ra.rar


                  #  Create threadpool for hornetq
                  asadmin create-threadpool  hornetq-ra-thread-pool


                  # Create resource adapter  config, setting NettyConnectorFactory.  (Note, this name changed between  2.0 and 2.1.  Also note the double backslashes).
                  asadmin  create-resource-adapter-config --threadpoolid hornetq-ra-thread-pool \
                     --property \
                     "ConnectorClassName=org.hornetq.core.remoting.impl.netty.NettyConnectorFactory:ConnectionParameters=host\\=localhost;port\\=5445:UserName=guest:Password=guest"  \
                    hornetq-ra


                  # Create a connection connection  pool.  Note we set the username password here rather than above since of  some weirdness on the part of gf or hq (??)

                  asadmin  create-connector-connection-pool --raname hornetq-ra  \
                     --connectiondefinition org.hornetq.ra.HornetQRAConnectionFactory \
                     --property UseTryLock=0:SessionDefaultType=javax.jms.Queue:UserName=guest:Password=guest \

                     --transactionsupport XATransaction \
                    hornetq-ra-connection-pool


                  #  Create a connector resource that uses the created just created  connection pool.  This is how we'll refer to this within code.

                  asadmin  create-connector-resource --poolname hornetq-ra-connection-pool  --description "HornetQ Connection Resource" hornetq-ra


                  #  If you want the default inbound adapter to be hornetq, set this global  jvm option.

                  asadmin create-jvm-options  -Dcom.sun.enterprise.connectors.inbound.ramid=hornetq-ra

                   

                  #  Restart domain to pick up jvm options.
                  asadmin stop-domain  ${DOMAIN_NAME}
                  asadmin start-domain ${DOMAIN_NAME}


                  #Ping  the pool

                  asadmin ping-connection-pool hornetq-ra-connection-pool


                  #  Gotchas

                  # An older version of netty also in the lib folder causes no  method exceptions.


                  ### Cleanup

                  asadmin  delete-jvm-options  -Dcom.sun.enterprise.connectors.inbound.ramid=hornetq-ra
                  asadmin  delete-connector-resource hornetq-ra
                  asadmin  delete-connector-connection-pool hornetq-ra-connection-pool
                  asadmin  delete-resource-adapter-config hornetq-ra
                  asadmin delete-threadpool  hornetq-ra-thread-pool
                  asadmin undeploy hornetq-ra
                  asadmin  stop-domain ${DOMAIN_NAME}
                  rm ${DOMAIN_DIR}/lib/netty.jar
                  rm  ${DOMAIN_DIR}/lib/hornetq-core-client.jar
                  rm  ${DOMAIN_DIR}/lib/hornetq-jms-client.jar
                  rm  ${DOMAIN_DIR}/lib/hornetq-logging.jar
                  asadmin start-domain  ${DOMAIN_NAME}

                   

                  Hack to get rid of glassfish errors around password and username (optional).

                   

                  HornetQRAManagedConnectionFactory.java: line 272 is where i picked to add this.

                   


                  /** Added for glassfish **/


                  public  String  getPassword(){
                     return ra.getPassword();
                  }


                   


                  /**  Added for glassfish **/
                  public String getUserName(){
                     return  ra.getUserName();
                  }

                   

                   

                  Glassfish Errors during redeployment

                  Messages On Redeploy

                   

                  [#|2010-07-14T11:44:57.988-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                  [#|2010-07-14T11:44:57.988-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                  [#|2010-07-14T11:44:57.988-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                  [#|2010-07-14T11:44:57.988-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                  [#|2010-07-14T11:44:57.988-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                  [#|2010-07-14T11:44:58.003-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                  [#|2010-07-14T11:44:58.003-0700|WARNING|glassfish3.0.1|javax.enterprise.system.container.ejb.mdb.com.sun.ejb.containers|_ThreadID=20;_ThreadName=Thread-1;|[MDBContainer] Current thread done cleanup()... |#]

                   

                   

                  Message when trying to send/receive message.

                  [#|2010-07-14T11:54:04.664-0700|SEVERE|glassfish3.0.1|org.hornetq.ra.inflow.HornetQMessageHandler|_ThreadID=29;_ThreadName=Thread-1;|Failed to deliver message
                  javax.ejb.EJBException: testing:InputWorker: Message-driven bean invocation closed by container
                          at com.sun.ejb.containers.MessageBeanContainer.beforeMessageDelivery(MessageBeanContainer.java:975)
                          at com.sun.ejb.containers.MessageBeanListenerImpl.beforeMessageDelivery(MessageBeanListenerImpl.java:72)
                          at com.sun.enterprise.connectors.inbound.MessageEndpointInvocationHandler.invoke(MessageEndpointInvocationHandler.java:134)
                          at $Proxy198.beforeDelivery(Unknown Source)
                          at org.hornetq.ra.inflow.HornetQMessageHandler.onMessage(HornetQMessageHandler.java:254)
                          at org.hornetq.core.client.impl.ClientConsumerImpl.callOnMessage(ClientConsumerImpl.java:823)
                          at org.hornetq.core.client.impl.ClientConsumerImpl.access$100(ClientConsumerImpl.java:46)
                          at org.hornetq.core.client.impl.ClientConsumerImpl$Runner.run(ClientConsumerImpl.java:941)
                          at org.hornetq.utils.OrderedExecutorFactory$OrderedExecutor$1.run(OrderedExecutorFactory.java:96)
                          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
                          at java.lang.Thread.run(Thread.java:619)
                  |#]

                   

                   

                   

                  Error messages seen in Hornetq

                  These happen regularily and I believe the relate to the Glassfish redployment problem...

                   

                  [hornetq-failure-check-thread] 11:55:56,377 WARNING [org.hornetq.core.server.impl.ServerSessionImpl]  Client connection failed, clearing up resources for session 2779e98e-8f79-11df-bda5-001c257aff40
                  [hornetq-failure-check-thread] 11:55:56,377 WARNING [org.hornetq.core.server.impl.ServerSessionImpl]  Cleared up resources for session 2779e98e-8f79-11df-bda5-001c257aff40
                  [hornetq-failure-check-thread] 11:55:56,377 WARNING [org.hornetq.core.protocol.core.ServerSessionPacketHandler]  Client connection failed, clearing up resources for session 2779e98e-8f79-11df-bda5-001c257aff40
                  [hornetq-failure-check-thread] 11:55:56,377 WARNING [org.hornetq.core.protocol.core.ServerSessionPacketHandler]  Cleared up resources for session 2779e98e-8f79-11df-bda5-001c257aff40

                   

                  >>>Message was edited by: Jacques Nadeau Added username and password definition to connection pool.  It seems that both Connection pool and resource adapter config need it to avoid having do the hack in HornetQRAManagedConnectionFactory.java.  Also removed the usexa property from the resource adapter config.