Quantcast
Channel: The JavaDude Weblog » glassfish
Viewing all articles
Browse latest Browse all 14

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

$
0
0

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:



Viewing all articles
Browse latest Browse all 14

Trending Articles