I am quite OK with the build-in JMS in Glassfish (OpenMQ), as long you dont want to access queues from external applications or you need an admin console to easily create, delete queues, send messages and browse the queues. ActiveMQ is a good alternative. Unfortunately we could not find any end2end description hot to get the couple Glassfish-ActiveMQ up and running (under Linux, Windows should be a quite similar affair).
This tutorial describes how to install and configure ActiveMQ as embedded JMS broker, and connect a MDB to it.
- Running Glassfish 3.1 instance (or later).
- Download the current ActiveMQ package
At the time of writing it is 5.5.0 (apache-activemq-5.5.0-bin.tar.gz)
- Add libraries to the Glassfish lib folder (GLASSFISH_HOME/glassfish/lib)
All files you find in the ActiveMQ package
Optional: Replace the log4j jars with logback logging (here the current versions)
- Download the separate resource adapter (link)
We could not make the generic resource adapter work (http://genericjmsra.java.net/)
(No longer included in the ActiveMQ package)
- Place the resource adapter jar file in the Glassfish lib folder (GLASSFISH_HOME/glassfish/lib)
Restart Glassfish if it is running.
- Deploy the resource adapter
- Create Resource Adapter Configuration
Select a threadpool and change these settings
- ServerUrl: vm://localhost:61616
- BrokerXmlConfig: broker:(tcp://localhost:61616)
Update 2011-08-02: Use 0.0.0.0 instead of localhost, otherwise you will get a Connection Refused error from external clients (from a different host)
- Add Connector Connection Pool ‘amqpool’
Second page with default settings
- Add new Connector Resource ‘amqres’
with previous pool ‘amqpool’
- Add Admin Object Resource‘amqmsg’
- Add JVM Settings
and restart Glassfish
- Download and deploy the ActiveMQ Console Web App (link)
- Run the admin Console(http://localhost:8080/activemq-web-console-5.5.)
- Create a queue with the same name as Admin Object Resource‘amqmsg’
Right now we already have a fully working ActiveMQ ‘inside’ our Glassfish. In Part 2 we create a simple Java SE app to write to the queue, in Part 3 we will create a MDB (message driven bean) to listen to the queue.
- Please note all above settings are made out-of-the-box. It is up to you to secure the instance with user-id’s and passwords, eventually change ports and so on.
- Starting up Glassfish should show a log like this
INFO: 2011-07-21 15:15:41,482 [ActiveMQ Broker] INFO PListStore - PListStore:activemq-data/localhost/tmp_storage started INFO: 2011-07-21 15:15:41,486 [ActiveMQ Broker] INFO BrokerService - Using Persistence Adapter: KahaDBPersistenceAdapter[/home/user/glassfish-3.1/glassfish/domains/domain1/activemq-data/localhost/KahaDB] INFO: 2011-07-21 15:15:42,379 [ActiveMQ Broker] INFO MessageDatabase - KahaDB is version 3 INFO: 2011-07-21 15:15:42,399 [ActiveMQ Broker] INFO MessageDatabase - Recovering from the journal ... INFO: 2011-07-21 15:15:42,399 [ActiveMQ Broker] INFO MessageDatabase - Recovery replayed 1 operations from the journal in 0.011 seconds. INFO: 2011-07-21 15:15:42,409 [ActiveMQ Broker] INFO BrokerService - ActiveMQ 5.5.0 JMS Message Broker (localhost) is starting INFO: 2011-07-21 15:15:42,409 [ActiveMQ Broker] INFO BrokerService - For help or more information please see: http://activemq.apache.org/ INFO: 2011-07-21 15:15:42,946 [ActiveMQ Broker] INFO TransportServerThreadSupport - Listening for connections at: tcp://localhost.localdomain:61616 INFO: 2011-07-21 15:15:42,947 [ActiveMQ Broker] INFO TransportConnector - Connector tcp://localhost.localdomain:61616 Started INFO: 2011-07-21 15:15:42,949 [ActiveMQ Broker] INFO BrokerService - ActiveMQ JMS Message Broker (localhost, ID:GISBORNE-55741-1311232542431-0:1) started
- There is a little display problem under JMS resources. The ActiveMQ resources are not displayed in the list, but on the left side.
- Thanks to Alphy for digging out a lot of above details.
- Manning: ActiveMQ in Action (http://www.manning.com/snyder/)
- ActiveMQ Documentation (http://activemq.apache.org/using-activemq-5.html)
- and dozens of forum threads all over the web.