GlassFish V2 and ActiveMQ 4.1
Posted by rampsarathy on March 20, 2007 at 2:54 AM EDT
- Install GlassFish V2 and ActiveMQ 4.1
GlassFish V2 : https://glassfish.dev.java.net/downloads/v2-b33e.html
ActiveMQ 4.1 : http://activemq.apache.org/activemq-410-release.html
- 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.
- activemq-core.jar
- activeio.jar
- commons-logging.jar
- backport-util-concurrent.jar
- Start the Active MQ - please refer to http://activemq.apache.org/run-broker.html
- Create the required destinations : http://activemq.apache.org/how-do-i-create-new-destinations.html 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.
- 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.
http://weblogs.java.net/blog/rampsarathy/archive/Main.java - Create the resource adapter configuration :
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 - 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
- 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 - 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 - 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
http://weblogs.java.net/blog/rampsarathy/archive/sun-ejb-jar.xml - 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.
The MDB sample is here The descriptors are : sun-ejb-jar.xml
ejb-jar.xml
Related Topics >>
Blog Links >>
- Login or register to post comments
- Printer-friendly version
- rampsarathy's blog
- 12679 reads






Comments
Hi there and thanks for the great article. Have you ...
by leonid.kogan - 2011-08-21 01:47
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