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

Last year I described all steps to get running with ActiveMQ embedded in Glassfish:

Some updates :
The current version of ActiveMQ is 5.7.0. Here some updated download links
activemq-web-console-5.7.0.war (link)
activemq-rar-5.7.0.rar (link)
activemq-ra-5.7.0.jar (link)
activemq-all-5.7.0.jar (from the main package)

Note: you need to re-deploy the resource adapter with version 5.7 and check all connector settings.

It works fine with Glassfish and Java JDK 1.7.07

I had issues with the firewall due to fact ActiveQM uses a fix registration port for JMX but dynamic ports for the communication port. The web-console was not accessible.
“Exception occurred while processing this request, check the log for more information!”

Web Console

[#|2012-10-18T07:42:09.249+0000|WARNING|glassfish3.1.2||_ThreadID=73;_ThreadName=Thread-2;|StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception Connection timed out
at Method)

There are ways to configure this for a standalone ActiveMQ instance with the parameters connectorPort and rmiServerPort but I didnt find out yet how to do this with the embedded version.
As a workaround I changed this setting -Djava.rmi.server.hostname from my hostname to localhost.

JVM Settings

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

In the third and final part of this tutorial we will crate a MDB (Message Driven Bean) that listens to our embedded ActiveMQ from Part 1.



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.


  • Running Glassfish 3.1 instance (or later).


My Review of Java Message Service

Originally submitted at O’Reilly



Java Message Service, Second Edition, is a thorough introduction to the standard API that supports “messaging” — the software-to-software exchange of crucial data among network computers. With this practical guide, you’ll learn how JMS can help you solve many architectura…

Old Topic, but a good starting point.

By AnotherJavaDude from Singapore on 10/29/2010
4out of 5

Pros: Well-written, Helpful examples, Accurate

Best Uses: Intermediate

Describe Yourself: Maker, Developer

Despite JMS being an “old” (in IT terms) piece of technology (API), you still find requirements for it in lots of projects and the basic needs of a messaging API are fully satisfied, even not updated since 2002.
This book is one of the few books covering the topic at all, and coming with code samples is the best you can get to get started with JMS. With a fair background of your application/messaging server and your favourite IDE you should be able to get the samples running.


Tutorial: Starting with Glassfish and JMS (Part 2)

Today we proceed with last weeks JMS tutorial and create a standalone java application that sends a message to a topic.

It puzzles me to have a client application that I need to start “from within”. Lets find out how an application looks like that can run by itself, connect to a JNDI server and sends a message to topic. The key information I took from this discussion (link, Thanks to Foli and TravelEntity) at

Using: Netbeans 6.5 and a local Glassfish V2

1. Lets create a standard SE java project. We call it “JMSClient”


JMSClient: New Java SE project

2. Import the necessary libraries

Applicationserver JNDI Lookup

Client Lib

(You find them in your glassfish home directory)


JMSClient: Libraries

3. The complete source

package jmsclient;

import java.util.Hashtable;
import java.util.Queue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Main {

    public static void main(String[] args) {

        Context jndiContext = null;
        ConnectionFactory connectionFactory = null;
        Connection connection = null;
        Session session = null;
        // ---- Same sample with a queue ----
        // Queue queue = null;
        Topic topic = null;
        MessageProducer messageProducer = null;
        MapMessage message = null;

        Hashtable properties = new Hashtable(2);
        properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory");
        properties.put(Context.PROVIDER_URL, "iiop://localhost:3700");

        try {
            jndiContext = new InitialContext(properties);
            connectionFactory = (ConnectionFactory)jndiContext.lookup("jms/ConnectionFactory");
            // ---- Same sample with a queue ----
            //queue = (Queue)jndiContext.lookup("jms/Queue");
            topic = (Topic)jndiContext.lookup("jms/Topic");

            connection = connectionFactory.createConnection();
            session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            // ---- Same sample with a queue ----
            //messageProducer = session.createProducer(queue);
            messageProducer = session.createProducer(topic);
            message = session.createMapMessage();

            // ---- Preparing Mapped Message ----
            message.setString("lastname", "Myer");
            message.setString("firstname", "Fred");
            message.setString("id", "0200");



        } catch (NamingException e) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
        catch (JMSException e) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, e);
        finally {


  • The tutorial is looking for a local server. Change (Context.PROVIDER_URL, “iiop://localhost:3700”) to the relevant server and port info.
  • We use a topic (publish/subscribe) in this sample. If you want to use a queue instead, change to the lines which are commented out and remove the topic related lines.

Tutorial: Starting with Glassfish and JMS

Remark 11.12.2010:
I seriously tried to make this running using Glassfish V3. Several hours in poking around with the various libraries, it just does not work. If ever someone comes around who found the solution, let us know !
Related posts: and

Remark 08.11.2010:
This is a very popular blog entry ! But it is from January 2009 and refers to Glassfish V2. The below tutorial does not work with Glassfish V3. I am currently reviewing it and creating an updated walk-through with the latest version(s). Stay tuned.

Remark 21.07.2011:
To all JMS fans, please consider ActiveMQ as alternative. I documented all necessary steps here (
I gave up on Glassfish JMS (at least for external apps).

Despite tons of material, downloads and websites on JAVA enterprise applications, tools and features, there are few sources only for “Let’s get started” styled tutorials. The Netbeans tutorial is often the best starting point (link).

I was reading about the background of JMS, some of the material is of a very theoretical nature and I tried to find some simple sample to get my hands dirty. A good short article on JMS in the glassfish context you can find at (link)

This tutorial describes the steps to get a most simple messaging application up and running implementing a one-to-many communication using topics, also called publish-subscribe. A enterprise client creates a message put it on a topic and a message-driven bean (MDB) retrieves the message.

Using: Netbeans 6.5 with installed Glassfish V2.

1. Creating a new JAVA EE project.

MyJMS Project

MyJMS Project: New Project

2. We call it MyJMS. Disable the web-application and enable application-client


MyJMS Project: New EE Application

3. We will have a project window with 2 subprojects for the EJB and the application client.


MyJMS Project

4. Before we start with the coding of the EJB and the client, we configure the applicationserver. Open the admin console via right click on the application server under services (Start the server first, if not done yet). You remember the default admin password for glassfish ? “adminadmin”.You better change if your box is open to outside world.


MyJMS: View Admin Console

In the admin console we create the ressources for the JMS topic.


MyJMS: Add Resources

Create a destination resource with JNDI name “jms/topic” and Resource type “javax.jms.topic” (rest default settings).
Create a connection factory with the JNDI name “jms/TopicFactory” (rest default settings, but remove username and password).

Continue reading