Glassfish V3.1 running embedded ActiveMQ for JMS (Part 1)

Updates 2012-10-18

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.

Pre-Requirements:

  • Running Glassfish 3.1 instance (or later).

Tutorial

  • Download the current ActiveMQ package
    At the time of writing it is 5.5.0 (apache-activemq-5.5.0-bin.tar.gz)

    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

    • activemq-all-5.5.0.jar
    • slf4j-api-1.5.11.jar
    • log4j-1.2.14.jar
    • slf4j-log4j12-1.5.11.jar

    Optional: Replace the log4j jars with logback logging (here the current versions)

    • slf4j-api-1.6.1.jar
    • logback-core-0.9.29.jar
    • logback-classic-0.9.29.jar
  • 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)

    • activemq-ra-5.5.0.jar
    • activemq-rar-5.5.0.rar
  • 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
    activemq-rar-5.5.0.rar

    Resource Adapter

    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)

    Resource Adapter Configuration

  • Add Connector Connection Pool ‘amqpool’
    Second page with default settings

    Connector Connection Pool

    Connector Connection Pool

     

  • Add new Connector Resource ‘amqres’
    with previous pool ‘amqpool’

    Connector Resource

  • Add Admin Object Resource‘amqmsg’

    Admin Object Resource

  • Add JVM Settings
    • -Dwebconsole.type=properties
    • -Dwebconsole.jms.url=tcp://localhost:61616
    • -Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi

    and restart Glassfish

    JVM Settings

  • Download and deploy the ActiveMQ Console Web App (link)
    activemq-web-console-5.5.0.war

    ActiveMQ Console

  • Run the admin Console(http://localhost:8080/activemq-web-console-5.5.)

    ActiveMQ Admin Console

  • Create a queue with the same name as Admin Object Resource‘amqmsg’

    New Queue

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.

Remarks:

  • 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.

References:

23 thoughts on “Glassfish V3.1 running embedded ActiveMQ for JMS (Part 1)

  1. Pingback: Tutorial: Starting with Glassfish and JMS « The JavaDude Weblog

  2. Hie i managed to setup activemq in glassfish
    however i get the following error
    INFO: Exception Occurred :java.lang.RuntimeException: REST Request ‘http://localhost:4848/management/domain/resources/connector-resource/amqpool’ failed with response code ‘404’.

    • Thanks for the help
      the resource and connection factory now seems ok
      i can send and receive messages from a java se client
      however my MDB can seem to pick up the messages
      i created a test queue name jms/testQueue

      and find attached my MDB code :

      @MessageDriven(mappedName = “jms/testQueue”, activationConfig = {
      @ActivationConfigProperty(propertyName = “acknowledgeMode”, propertyValue = “Auto-acknowledge”),
      @ActivationConfigProperty(propertyName = “destinationType”, propertyValue = “javax.jms.Queue”)
      })
      public class TestMDB implements MessageListener {

      public TestMDB() {
      }

      @Override
      public void onMessage(Message message) {
      if(message instanceof TextMessage){
      try {
      TextMessage message1 = (TextMessage)message;
      System.out.println(“########## ” + message1.getText());
      } catch (JMSException ex) {
      Logger.getLogger(TestMDB.class.getName()).log(Level.SEVERE, null, ex);
      }
      }
      }
      }

      i get the following in my log as well :

      INFO: RAR8029: Resource [ jms/testQueue ] of type [ aor ] is not enabled
      INFO: RAR8029: Resource [ jms/testQueue ] of type [ aor ] is not enabled

  3. Pingback: Glassfish V3.1 running embedded ActiveMQ for JMS (Part 3) « The JavaDude Weblog

  4. RAR8029: Resource [ jms/testQueue ] of type [ aor ] is not enabled

    I also got this once. Did u restart glassfish after change.Also check in domain.xml whether enabled=false for this resource.if false,change to true and restart.

  5. Hi,

    I am using Glassfish 3.1.1. I am able to deploy activemq-rar-5.5.0 application successfully and create Msg Resources. However I am not able to deploy activemq-web-console-5.5.0.war. I get the error: WebConsoleStarter is not found.

    I have tried many option, like building active-web-console-5.5.0 by downloading source code. Nothing has worked. Can you please guide me.

  6. Pingback: Integracja ActiveMQ 5.x z Glassfish 3.1 « Zapiski programisty

  7. Pingback: Jms | TagHall

  8. Pingback: How to connect Glassfish 3 to an external ActiveMQ 5 broker « Geert Schuring

  9. Hi, nice post. A colleague used it word for word to set up our activeMQ instance in Glassfish3 with great success. However, he’s also java dude whereas I’m not, so we’ve still got a problem – I’d like to be able to connect to it via STOMP.

    I’ve done exactly that just fine with activeMq running in isolation by just adding the following lines to activemq.xml:

    (as per http://activemq.apache.org/stomp.html)

    As the glassfish deployment doesn’t take across the activemq.xml file from the source, do you have any idea where we could add this to enable STOMP?

    It’s probably super simple, I just can’t figure it out.

    Thanks very much!

    • For anyone else that has this question – I had the same problem except for MQTT, what you do is add the extra broker to the end of the first in the BrokerXmlConfig properties in “Resource Adapter Config”… mine looks like this:

      broker:(tcp://0.0.0.0:61616,mqtt://0.0.0.0:7771)

      You will then need to add any required jars out of the ActiveMQ zip file to the lib folder where you put everything else above, restart GlassFish and it should work. This page kind of shows the format:

      http://activemq.apache.org/run-broker.html

      According to the ActiveMQ page on stomp ( http://activemq.apache.org/stomp.html ) – the broker would look like this:

      broker:(tcp://0.0.0.0:61616,stomp://localhost:61613)

  10. PS – I realise that’s asking quite a lot given the amazing detail of the post itself, but you seem like a bit of an expert on the activemq-glassfish subject! Thanks!

  11. Pingback: Glassfish V3.1 running embedded ActiveMQ for JMS (Updates) | The JavaDude Weblog

  12. I am trying to integrate Active MQ with Glassfish Server.

    I am following this link.

    Glassfish V3.1 running embedded ActiveMQ for JMS (Part 1)

    I get below error

    C:\glassfish\glassfishv3\glassfish\bin>asadmin deploy c:/temp/activemq-web-conso le-5.8.0.war

    com.sun.enterprise.admin.cli.CommandException: remote failure: There is no insta lled container capable of handling this application com.sun.enterprise.deploy.sh ared.FileArchive@118b940

    Is there any solution to this problem?

    • Did you install the resource adapter first ?
      Did you put all required lib files into the lib folder ?
      I noticed with 5.8.0 there are some changes in the required libs (which I didnt require earlier for my 5.7.0 installation)

  13. Yes, I have installed resource adapter and also copied the requreid files in the lib folder.

    I am not sure deploying Active MQ web console in Glassfiosh is really mandatory activity?

    We can run connect to Active MQ Web UI seperately, without glassfish?

    • Yes, the console is not mandatory.
      You get the same error through the admin console ? What error stack you get in the server.log ?

Leave a comment