Configuring JMS Resources in GlassFish: Part 2

GlassFish Administration

December 2009


Administer and configure the GlassFish v2 application server

Configuring Open MQ using standalone tools

Open MQ is shipped with a collection of utilities that can be used to configure and administer its runtime environment and resources. In this section, we provide a brief introduction to these utilities. For a detailed description of these utilities, you can refer to the Open MQ document set, located at

Starting and stopping the Open MQ broker

The imqbrokerd utility is used to start a message broker. To start the default broker configured for GlassFish, open a command-line terminal, and enter the following commands:

# cd $AS_INSTALL/imq/bin
# ./imqbrokerd -tty

You should see an output describing the information about the broker, and the confirmation of the successful start of the broker.

If we do not specify a broker name, the imqbrokerd command will try to start the default broker named imqbroker. We can also supply a name <broker_name>. If the broker named <brokername> is already created, then the imqbrokerd command starts it; otherwise, a new broker of this name is created and then started.

To shutdown the message broker, enter Ctrl+C in the terminal where imqbrokerd is running.

Refer to the Open MQ documentation for information on how to run Open MQ brokers as a service.

Administering the Open MQ Broker using imqcmd

The main CLI utility we use to manage the Open MQ is imqcmd. It supports a long list of commands that can be used to create, destroy, modify, and display the information of a resource, such as a broker or a physical destination, and so on. To show the commands and options supported, enter the following commands in a terminal:

# cd $AS_INSTALL/imq/bin
# ./imqcmd -h

As the first example, we can use the following command to display the status information of the currently running broker:

# cd $AS_INSTALL/imq/bin
# ./imqcmd query bkr -u admin

Once you are prompted to enter the password, enter the default password admin. You should see an output describing the information regarding the currently running broker.

We can store the password in a password file and use the -passfile option to point to this file.

As another example, the following command queries the physical queue destination named PSQueueDest, and displays its information in the command-line terminal.

# cd $AS_INSTALL/imq/bin
# ./imqcmd query dst -t q -n PSQueueDest -u admin

In this example, the option –t specifies the type of the destination as a topic, and the option –n PSQueueDest specifies the name of the physical destination.

Refer to the help information and the MQ Administration Guide for a detailed description of the imqcmd utility.

Using the imqadmin administration console

The imqadmin utility is the primary GUI-based administration console of the Open MQ. It supports more of the functions of the imqcmd utility. Besides, it can also manage and confi gure the administration objects used by applications, such as specifying a naming service provider, and registering connection factories and destination resources in the naming service.

To start the administration console, open a command-line terminal, and type the following command:

# cd $AS_INSTALL/imq/bin
# ./imqadmin

You should see the administrator console window displayed. The administration console's navigation pane contains two top-level nodes, Brokers and Object Stores. The Brokers node organizes all the registered Open MQ brokers being managed by the administration console. The Object Stores node organizes the naming service providers to which the JMS administration objects (connection factories and destination resources) are registered.

The following steps walk you through the typical process of adding a broker, and managing the broker resources.

  1. From the navigation pane of the administrator console, right click the Brokers node, and choose Add Broker. You should see a dialog box displayed.
  2. Fill out the Add Broker dialog according to the following screenshot, enter admin in the password field, and click OK.
  3. GlassFish Administration

    Now you should see the broker PSBroker is listed under the Brokers node with a red X on its icon, which indicates that the broker is not currently connected to the administrator console yet.

    Adding a broker does not create or start a new physical broker. It merely registers an existing broker to the administration console, and once we connect the administration console, we will be able to manage the resources of the broker.

  4. From the navigation pane, right click PSBroker under the Brokers node, and choose Connect to Broker. Once you connect to the broker, you should see the red X disappeared on the Brokers node.
  5. From the navigation pane, click Services under PSBroker. In the result pane, you should see all the available connection services listed for the broker, as shown in the following screenshot.
  6. GlassFish Administration

  7. From the navigation pane, right click Destinations under PSBroker, and select Add Broker Destination. You should see a dialog displayed.
  8. Enter PSQueueDest in the Destination Name field, select Queue radio button if not already selected. Keep all the other settings unchanged, and click OK to add the physical destination.
  9. From the navigation pane, click Destinations under PSBroker, the newly added PSQueueDest should appear.

With physical destinations created, we can go through the following steps to configure the connection factory and destination resources in the Object Stores:

  1. Right click the Object Stores node in the navigation pane, and choose Add Object Store.
  2. Enter the following information in the dialog, and click OK to add the Object Store.
  • Enter PSStore in the Object Store Label field.
  • From the Name pull-down menu, select java.naming.factory.initial, and enter com.sun.jndi.fscontext.RefFSContextFactory in the value field.
  • Click the Add button. These steps set the JNDI service provider you will use, to a filesystem based object store.
  • From the Name pull-down menu, select java.naming.provider.url, and enter file:///tmp in the value field.
  • Click the Add button. These steps set the exact location of the object store to the directory /tmp.

In the navigation pane, you will see the object store PSStore you just added is listed under the Object Stores node with a red X on its icon, which indicates that the object store is not currently connected to the administrator console yet.

  • From the navigation pane, right click PSStore under the Object Stores node, and choose Connect to Object Store. Once you connect to the object store, you should see that the red X has disappeared on the Object Stores node.
  • From the navigation pane of the Open MQ administrator console, right click Destinations under PSStore node, and select Add Destination Object. You should see a dialog box displayed.
  • Enter PSQueue in the Lookup Name field, select Queue from the Destination Type radio button. Enter PSQueueDest in the Destination Name field, and click OK to add the queue destination, as shown in the following screenshot.
  • GlassFish Administration

    Now that we have seen how Open MQ is integrated with GlassFish, let's look at another very popular open source JMS implementation, ActiveMQ.

    Configuring ActiveMQ for GlassFish

    ActiveMQ is a very popular open source provider that is fully JMS 1.1 compliant. Besides, Active MQ has several very appealing features, such as cross language support for client development, high availability support, and support for REST API, and so on. For a more detailed description of the ActiveMQ product, visit the ActiveMQ project website hosted by Apache:

    GlassFish is shipped with a generic JMS JCA resource adapter. In this section, we use ActiveMQ as an example to demonstrate how this generic resource adapter allows GlassFish to integrate with third-party JMS providers.

    Many JMS providers, including ActiveMQ includes its own JCA resource adapters for integrating with a Java EE application server. In this book, we do not cover this topic. You can refer to the JMS provider's documentation to enable this. For example, integrating ActiveMQ into GlassFish using ActiveMQ's resource adapter is actually quite similar to using the GlassFish resource adapter.

    Installing and configuring ActiveMQ

    The first step of integrating with ActiveMQ is to install it. Installing ActiveMQ is very straight forward. Simply download the latest ActiveMQ binary distribution (ZIP format for Window, and GZIP for UNIX/Linux/Mac OS X) from, and extract it to a target directory. For example, /opt. Next, let's start the ActiveMQ broker with the following commands:

    # cd /opt/apache-activemq-5.3.0/bin
    # ./activemq-admin start

    There are a variety of ways to configure ActiveMQ. The most comprehensive mechanism is to work with XML-based configuration files. This approach can be used to define all aspects of a message broker and its components, such as message destination. For a detailed discussion, please refer to the ActiveMQ documentation for more information on this.

    ActiveMQ also provides a simple web-based user interface for basic administrative tasks, such as creating/deleting message destinations (both topics and queues), sending messages to a destination for testing, and browsing messages in a destination, and so on.

    Now let's use the administrative user interface to configure a queue. To do this, complete the following steps:

  • Open a browser, and access the ActiveMQ admin URL http://localhost:8161/admin. The ActiveMQ administration page appears.
  • Click Queues.
  • The browser lists the message queues configured for the ActiveMQ broker. By default, a queue named example.A is configured, as shown in the following screenshot.

    GlassFish Administration

    In the next section, we show you how to integrate this sample queue into GlassFish.


    Working with GlassFish generic resource adapter

    In this section, we show you the necessary configuration steps in GlassFish to integrate with ActiveMQ.

    Configuring the GlassFish server classpath

    In order to integrate with ActiveMQ, we need to add the following files to the GlassFish server classpath:


    To add these files to the GlassFish classpath, complete the following steps:

    1. Log on to the GlassFish Admin Console.
    2. Click the Application Server node in the navigation panel.
    3. Click JVM Settings tab, and then Path Settings tab in the main content panel.
    4. Add the full paths of the files to the Classpath Suffix field. (Make sure you use the appropriate file separator).
    5. Click Save, and then restart GlassFish.

    Deploying the generic resource adapter

    The generic resource adapter shipped with GlassFish is located at $AS_INSTALL/lib/addons/resourceadapters/genericjmsra/genericra.rar. Like all resource adapters, it can be deployed as a standalone connector module, or it can be bundled inside an enterprise application and deployed with the application. The difference is that if it is deployed along as part of an application, it will only be visible to that application. In this article, we deploy the resource adapter as a standalone connector module.

    To do this, first, we need to create a resource-adapter-config object in the GlassFish domain configuration. This is one of the few tasks that can only be executed using the asadmin CLI utility, as shown in the following command:

    # cd $AS_INSTALL/bin
    # asadmin create-resource-adapter-config --property SupportsXA=true:RMPo
    brokerURL=tcp:// genericra

    Make sure the second command is entered in one single line. Essentially, this command specifies the connection factory classes the Generic Resource Adapter will use to interact with ActiveMQ, and it also specifies some essential properties that contain the information about the ActiveMQ provider. For example, the ConnectionFactoryProperties property's value, URL=tcp:// specifies the listening port of the ActiveMQ broker.

    The in the command is to escape the = sign in the property value. If you are running the command on Windows platform, you only need to use a single . Also, for ActiveMQ, make sure we specify the property supportsXA=true in the command. Otherwise, the generic resource adapter won't work.

    After creating the resource adapter configuration, we can deploy the resource adapter using the following command:

    # cd $AS_INSTALL/bin
    # ./asadmin deploy ../lib/addons/resourceadapters/genericjmsra/genericra.

    We can also deploy the resource adapter as a connector module using the Admin Console. The command-line based deployment is found to be faster.

    Creating the connector resources

    After deploying the resource adapter, we can now create necessary connector resources to enable the integration with ActiveMQ. These resources can be created using the Admin Console or the asadmin CLI. This section shows you how to do it using the CLI. In the Admin Console, these tasks are grouped under the Connectors node under Resources. First, we need to create a connector connection pool:

    # cd $AS_INSTALL/bin
    # ./asadmin create-connector-connection-pool --raname genericra
    --connectiondefinition javax.jms.QueueConnectionFactory
    --transactionsupport XATransaction AMGConnectionFactoryPool

    Next, we can create a connector connection factory using the AMGConnectionFactoryPool we just created:

    # cd $AS_INSTALL/bin
    # ./asadmin create-connector-resource --poolname AMGConnectionFactoryPool

    Finally, we can create a connector administration object as follows:

    # cd $AS_INSTALL/bin
    # ./asadmin create-admin-object --raname genericra --restype javax.
    jms.Queue --property DestinationProperties=PhysicalName=example.A jms/

    After these steps, sample queue, example.A in the ActiveMQ installation becomes an accessible JMS resource. For example, we can develop an MDB to listen to all the messages sent to this queue.


    This article provides you with an introduction to configuring JMS resources in GlassFish. At this point, you should be familiar with the Open MQ component that is built into GlassFish, and you should understand how to use the provided JCA resource adapter to integrate other JMS service providers with GlassFish. This article also shows you how to configure the MDB container, which allows us to configure the runtime environment for message-driven beans.

    [ 1 | 2]

    If you have read this article you may be interested to view :

    Books to Consider

    comments powered by Disqus

    An Introduction to 3D Printing

    Explore the future of manufacturing and design  - read our guide to 3d printing for free