Skip to main content

GlassFish V2 and ActiveMQ 4.1

Posted by rampsarathy on March 19, 2007 at 11:54 PM PDT



Configure_GenericJMSRA_For_ActiveMQ
content="text/html; charset=ISO-8859-1">



The previous blog entries showed how JMS providers like Jboss Messaging and MantaRay could be used with GlassFish. ActiveMQ is also one such JMS provider href="http://activemq.apache.org/">http://activemq.apache.org/
, the following steps describe the configurations required to use ActiveMQ with GlassFish.

  1.  Install GlassFish V2 and ActiveMQ 4.1

    GlassFish V2 : href="https://glassfish.dev.java.net/downloads/v2-b33e.html">https://glassfish.dev.java.net/downloads/v2-b33e.html

    ActiveMQ 4.1 : href="https://glassfish.dev.java.net/downloads/v2-b33e.html">http://activemq.apache.org/activemq-410-release.html

  2. Modify the glassfish domain's (default domain is domain1)
    classpath to add ActiveMQ4.1 jars
    located in ActiveMQ installation lib directory. The asadmin GUI
    could
    be used to
    modify a domain's classpath. Open a browser and type the url of the
    application server admin GUI - http://hostname:adminport. Go to
    Application Server -> JVM Settings -> Path Settings . Add
    an
    entry for the jar files shown below [comma-separated as shown below] in
    the classpath suffix. Restart the application server domain for these
    changes to take
    effect.    
      1. activemq-core.jar
      2. activeio.jar
      3. commons-logging.jar
      4. backport-util-concurrent.jar
  3.  Start the Active MQ - please refer to href="http://activemq.apache.org/run-broker.html">http://activemq.apache.org/run-broker.html  
     
  4. Create the required destinations : href="http://activemq.apache.org/how-do-i-create-new-destinations.html">
    http://activemq.apache.org/how-do-i-create-new-destinations.htm href="http://activemq.apache.org/how-do-i-create-new-destinations.html">l
    shows how destinations can be created in ActiveMQ. 2 queue
    destinations are required, "Receive" from which we will receive the
    messages and "Send" to which we will respond back from our MDB. 
  5. Create the jndi bindings : Create a File system JNDI object store
    to bind ActiveMQ JMS
    administered objects.  The following link shows a code snippet
    that creates a FS
    object store and binds the required ActiveMQ objects to the jndi tree.

               
               
          href="http://weblogs.java.net/blog/rampsarathy/archive/Main.java">http://weblogs.java.net/blog/rampsarathy/archive/Main.java
  6. Create the resource adapter configuration : style="font-style: italic;">

    asadmin
    create-resource-adapter-config --user <adminname>
    --password
    <admin password> --property
    SupportsXA=true:ProviderIntegrationMode=jndi:RMPolicy=OnePerPhysicalConnection:

    JndiProperties=java.naming.factory.initial\\=com.sun.jndi.fscontext.RefFSContextFactory

    java.naming.provider.url\\=file://space/activemqobjects:LogLevel=FINEST
    genericra
  7. Deploy the resource adapter using the asadmin deploy
    command, as shown below. In the image above, see Generic JMS
    RA deployed in the application server.  
       
        $ asadmin deploy --user admin --password
    adminadmin
    <location of the generic resource adapter rar file>

    Generic JMS RA is present in
    ${GLASSFISH_HOME}/lib/addons/resourceadapters/genericjmsra/genericra.rar style="font-style: italic;">

  8. In order to configure a JMS Connection
    Factory, using the Generic
    Resource Adapter for JMS, a Connector connection pool and resources
    needs to be created in the application server, as shown below.

    #Creates a Connection Pool called inpool and points to XAQCF created in
    Active MQ

    asadmin create-connector-connection-pool --raname genericra
    connectiondefinition javax.jms.QueueConnectionFactory
    --transactionsupport  XATransaction --property
    ConnectionFactoryJndiName=activemqconnectionfactory inpool

    #Creates a Connection Pool called outpool and points to XATCF created
    in Active MQ

    asadmin create-connector-connection-pool --raname genericra
    connectiondefinition javax.jms.QueueConnectionFactory
    --transactionsupport  XATransaction --property
    ConnectionFactoryJndiName=activemqconnectionfactory outpool

    #Creates a connector resource named jms/inboundXAQCF and
    binds this resource to JNDI for applications to use.

    asadmin create-connector-resource --poolname inpool jms/inboundXAQCF

    Note: Though the inbound
    configuration of the RA happens through the
    activation specification, a pool has to be created to make sure that
    the transaction recovery happens when the application restarts. This is
    because the transaction manager does recovery only for connector
    resources that are registered in domain.xml.

    #Creates a connector resource named jms/outboundXAQCF and
    binds this resource to JNDI for applications to use.

    asadmin create-connector-resource --poolname outpool jms/outboundXAQCF
  9. For JMS Destination Resources, an administered object needs to
    be
    created. jms/inqueue [pointing to Generic JMS
    RA and Receive] created in the application server.

    #Creates a javax.jms.Queue Administered Object and binds it to
    application server's JNDI tree at
    jms/inqueue and points to inqueue created in ActiveMQ.

    asadmin create-admin-object --raname genericra --restype
    javax.jms.Queue --property DestinationJndiName=Receive jms/inqueue

    #Creates a javax.jms.Topic Administered Object and binds it to
    application server's JNDI tree at
    jms/outqueue and points to outqueue created in ActiveMQ.

    asadmin create-admin-object --raname genericra --restype
    javax.jms.Queue --property DestinationJndiName=Send  jms/outqueue
  10. Deployment descriptors:

    The deployment descriptors need to take into account the resource
    adapter and the connection resources that have been created. A sample
    sun-ejb-jar.xml for a Message Driven Bean that listens to a destination
    called inqueue  in ActiveMQ, and publishes back reply messages to
    a
    destination resource named jms/outqueue  is available here

                href="http://weblogs.java.net/blog/rampsarathy/archive/sun-ejb-jar.xml">http://weblogs.java.net/blog/rampsarathy/archive/sun-ejb-jar.xml
  11. The business logic encoded in Message Driven Bean could then
    lookup the
    configured QueueConnectionFactory/Destination resource to create a
    connection and reply to the received message. style="font-style: italic;">




The MDB sample is
here
The descriptors are :
sun-ejb-jar.xml


ejb-jar.xml

Related Topics >>

Comments

&nbsp;Hi there and thanks for the great article. Have you ...

Hi there and thanks for the great article.

Have you tried this for GF 3.3.1?

This would be very appreciated if you could provide the manual for this one...

Kind regards,

Leonid Kogan