7.3. Manual Configuration and Deployment

Under the covers, the console creates a Geronimo deployment plan for the JMS resource group and then deploys the appropriate RAR file with that plan using the same deployment logic that the command-line deployer uses. After deploying a resource group, if you look at the list of deployed RAR files, you'll see an entry for the new group.

[Note]Note

The name (or configId) of the deployed RAR file is not important except to stop or undeploy it. When application modules want to refer to the JMS resources, they'll use the names configured in the connection factory or destination screens in the console.

In other words, the console is not doing anything special, and a JMS resource group can be configured and deployed manually. This may be especially useful if you want to deploy the same resource to multiple servers, or save the configuration for every developer to apply to their local instance later. This section describes how to configure and deploy JMS resource groups using the underlying text files and command-line tools.

7.3.1. JMS Resource Group Configuration

The configuration information required for one or more JMS resources is typically combined into a single ActiveMQ RAR deployment plan. It uses the standard Connector deployment options described in Chapter 13, J2EE Connectors (RARs) [DRAFT (1.0)], though the most important options for JMS are covered here.

A typical resource group deployment plan would look like this:

Example 7.1. JMS Resource Group Deployment Plan

<connector
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.0"
    configId="MyJMSResources"
    parentId="geronimo/activemq-broker/1.0/car">

  <resourceadapter>
    <!-- how to connect to the JMS Server -->
    <resourceadapter-instance>
      <resourceadapter-name>
        My JMS Resources
      </resourceadapter-name>
      <config-property-setting name="ServerUrl">
        tcp://localhost:61616
      </config-property-setting>
      <config-property-setting name="UserName">
        not needed
      </config-property-setting>
      <config-property-setting name="Password">
        not needed
      </config-property-setting>
      <workmanager>
        <gbean-link>DefaultWorkManager</gbean-link>
      </workmanager>
    </resourceadapter-instance>
    <!-- defines a ConnectionFactory -->
    <outbound-resourceadapter>
      <connection-definition>
        <connectionfactory-interface>
          javax.jms.ConnectionFactory
        </connectionfactory-interface>
        <connectiondefinition-instance>
          <name>MyConnectionFactory</name>
          <implemented-interface>
            javax.jms.QueueConnectionFactory
          </implemented-interface>
          <implemented-interface>
            javax.jms.TopicConnectionFactory
          </implemented-interface>
          <connectionmanager>
            <xa-transaction>
              <transaction-caching />
            </xa-transaction>
            <single-pool>
              <max-size>10</max-size>
              <min-size>0</min-size>
              <blocking-timeout-milliseconds>
                5000
              </blocking-timeout-milliseconds>
              <idle-timeout-minutes>
                0
              </idle-timeout-minutes>
              <match-one/>
            </single-pool>
          </connectionmanager>
        </connectiondefinition-instance>
      </connection-definition>
    </outbound-resourceadapter>
  </resourceadapter>
  <!-- defines a Topic -->
  <adminobject>
    <adminobject-interface>
      javax.jms.Topic
    </adminobject-interface>
    <adminobject-class>
      org.activemq.message.ActiveMQTopic
    </adminobject-class>
    <adminobject-instance>
      <message-destination-name>
        MyTopic
      </message-destination-name>
      <config-property-setting name="PhysicalName">
        MyTopic
      </config-property-setting>
    </adminobject-instance>
  </adminobject>
  <!-- defines a Queue -->
  <adminobject>
    <adminobject-interface>
      javax.jms.Queue
    </adminobject-interface>
    <adminobject-class>
      org.activemq.message.ActiveMQQueue
    </adminobject-class>
    <adminobject-instance>
      <message-destination-name>
        MyQueue
      </message-destination-name>
      <config-property-setting name="PhysicalName">
        MyQueue
      </config-property-setting>
    </adminobject-instance>
  </adminobject>
</connector>

This rather dense deployment plan has 4 basic sections:

  1. The connector header

  2. Settings to connect to the message broker

  3. ConnectionFactory definitions

  4. Queue and Topic definitions

7.3.1.1. The Connector Header

The important elements in the connector header are:

configId

A unique name for this configuration. If the JMS resources are deployed server-wide, the name specified here can be passed to the deploy tool to start or stop the JMS configuration.

parentId

If a parentId is specified, this configuration will become a child of that one. The value specified as the parentId needs to match the configId specified for the parent configuration. Usually the JMS resource configuration is set to be a child of the message broker configuration, so the objects declared here have direct access to the server resources (through their parent ClassLoader) -- this is required in order to use the in-VM transport, and recommended in any case to resolve dependencies and startup ordering. (For more information on the Geronimo ClassLoader hierarchy, see Section 4.4, “ClassLoaders in Geronimo”.)

7.3.1.2. Message Broker Connection Settings

The resourceadapter-instance block contains the settings used to connect to the message broker. They are:

resourceadapter-name element

A name used to identify this resource adapter. This setting is not used elsewhere, and can be whatever you want.

ServerUrl configuration property

The method used to contact the message broker. This should match one of the ActiveMQConnectors deployed as part of the message broker.

UserName configuration property

A user name used to connect to the message broker. Not needed for the basic ActiveMQ message broker.

Password configuration property

A password used to connect to the message broker. Not needed for the basic ActiveMQ message broker.

workmanager element

A work manager handles certain tasks on behalf of the resource adapter. The name specified in the nested gbean-link element must match a WorkManager instance running in Geronimo. Unless you have manually configured a WorkManager, leave this set to DefaultWorkManager.

[Tip]Tip

The work manager handles providing worker threads to a J2EE Connector, typically using a thread pool instead of (in the case of JMS) creating a separate thread to deliver every message. A custom work manager might be used to provide different threading behavior, such as higher-priority threads for a certain JMS configuration. However, this sort of change has not been tested with the current release.

7.3.1.3. ConnectionFactory Settings

The outbound-resourceadapter block contains the ConnectionFactory settings. In general, not much needs to be customized for the ConnectionFactory other than the name. However, note that you are actually configuring a pool of ConnectionFactory instances that will be shared across the JMS clients. The important elements in this block are:

connectionfactory-interface

Should normally be javax.jms.ConnectionFactory (though you could use javax.jms.QueueConnectionFactory or javax.jms.TopicConnectionFactory if you want a more restrictive connection factory).

name

The name that other modules will use to refer to this ConnectionFactory.

implemented-interface

Lists any specific interfaces that the ConnectionFactory should implement, in addition to the standard interface declared in the connectionfactory-interface element. The values here allow you to cast that to either a QueueConnectionFactory or TopicConnectionFactory, in addition to the generic ConnectionFactory.

max-size

The maximum size of the ConnectionFactory connection pool. Because of the pooling, this is also the maximum number of simultaneous connections allowed.

min-size

The minimum size of the connection pool. If the pool falls below this size, it will be refilled to the minimum size. However, the pool is not initialized to this size until the first time a connection attempt is made. The default value is 0.

blocking-timeout-milliseconds

If a caller requests a connection and all the ConnectionFactories in the pool are in use, the caller will wait this long for a ConnectionFactory to become available. If the timeout expires without an available ConnectionFactory, an exception will be thrown.

idle-timeout-minutes

This interval defines how often the pool is checked for unused connections. If during that check any individual connection has been unused for at least this long, it will be closed and removed from the pool. The default value of 0 disables idle timeouts.

For a more extensive discussion of the connectionmanager settings, see Section 13.3.2.2.1, “Connection Manager Configuration”.

7.3.1.4. Topic or Queue Settings

The adminobject block contains a reference to a Topic or Queue. Any number of adminobject blocks may be included, to configure as many destinations as you like. In many cases, multiple adminobjects may be present for the same underlying Topic or Queue -- this is because the adminobject is essentially the glue between message-destination objects declared in J2EE deployment descriptors, and the actual physical destinations. In the case where several J2EE modules use different names to refer to the same destination, you'll need several adminobject definitions to map all of those to the same destination.

The important settings in this block are:

adminobject-interface element

Should be javax.jms.Topic or javax.jms.Queue for a Topic or Queue, respectively.

adminobject-class element

Similarly should use org.activemq.message.ActiveMQTopic or org.activemq.message.ActiveMQQueue for a Topic or a Queue, respectively.

message-destination-name element

A name that application modules (like EJBs or web applications) will use to refer to this destination in their configuration information.

PhysicalName configuration property

The name of the actual Topic or Queue in the JMS Server. Different adminobjects can refer to the same Topic or Queue if the physical names match.

7.3.2. JMS Resource Deployment

With the deployment plan and the ActiveMQ RAR (located at geronimo/repository/activemq/rars/activemq-ra-3.2.1.rar), you can deploy the JMS resources.

7.3.2.1. Server-Wide Deployment

First you should save the JMS Resource deployment plan to a file like jms-resource-plan.xml (the name can be anything you like). Then you can deploy the resource configuration using a command like this:

java -jar bin/deployer.jar deploy jms-resource-plan.xml \
        repository/activemq/rars/activemq-ra-3.2.1.rar

Note that this example assumes that the server is running, and it can be run from any directory, so long as you point it to the deployer JAR in geronimo/bin and the correct plan file and RAR locations. The two arguments should point to the ActiveMQ RAR file and the JMS deployment plan (the order doesn't matter). If the server is not running, you can use the command distribute instead of deploy, though then you'll still have to start the configuration once the server is running. For more information on deployment commands, see Section 10.4, “The Deploy Tool”.

7.3.2.2. Application-Scoped Deployment

To deploy application-scoped JMS Resources, you'll include the ActiveMQ RAR as a module in your application EAR. First you should save the JMS Resource deployment plan to a file like jms-resource-plan.xml (the name can be anything you like). Then you need to add that along with the ActiveMQ RAR to your EAR.

For example, the EAR structure might look like this:

jar -tf my-app.ear
  my-web-app.war
  my-ejbs.jar
  activemq-ra-3.2.1.rar
  jms-resource-plan.xml
  META-INF/application.xml
  META-INF/geronimo-application.xml

Notice the ActiveMQ RAR and the JMS Resource deployment plan. You should add a reference to the ActiveMQ RAR to the standard META-INF/application.xml deployment descriptor, and add a reference to the JMS Resource deployment plan to the META-INF/geronimo-application.xml deployment plan. This might be the only entry in the geronimo-application.xml file, so you'll need to create that file if you don't have one already.

The application.xml file for the EAR above would look like this:

META-INF/application.xml

<application 
       xmlns="http://java.sun.com/xml/ns/j2ee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
       http://java.sun.com/xml/ns/j2ee/application_1_4.xsd"
       version="1.4">
    <module>
        <ejb>my-ejbs.jar</ejb>
    </module>
    <module>
        <web>
            <web-uri>my-web-app.war</web-uri>
            <context-root>/my-web-app</context-root>
        </web>
    </module>
    <module>
        <connector>activemq-ra-3.2.1.rar</connector>
    </module>
</application>

Notice the final module entry for the RAR.

The geronimo-application.xml file identifying the JMS Resource deployment plan would look like this:

META-INF/geronimo-application.xml

<application
  xmlns="http://geronimo.apache.org/xml/ns/j2ee/application-1.0"
  configId="MyApplication">
    <module>
        <connector>activemq-ra-3.2.1.rar</connector>
        <alt-dd>jms-resource-plan.xml</alt-dd>
    </module>
</application>

Using the alt-dd element, the deployment plan for the application indicates that the JMS Resource deployment plan for the connector is included as a separate file in the EAR, instead of being packaged into the RAR. The elements here look very similar to the elements in the standard application.xml deployment descriptor, but if we specify an alt-dd there it means an alternate standard J2EE deployment descriptor, whereas specifying the alt-dd here means an alternate Geronimo deployment plan for the connector.

With this configuration, the JMS resources will be started when the application is started.

[Tip]Tip

For more information on the geronimo-application.xml file, see Chapter 15, Enterprise Applications (EARs) [DRAFT (1.0)].

7.3.2.3. Client-Scoped Deployment

To deploy client-scoped JMS Resources, you'll refer to a common copy of the ActiveMQ RAR. Make sure it appears in geronimo/repository/activemq/rars for the client's Geronimo installation.

Module-scoped JMS Resources are declared in the Geronimo deployment plan for the module that should have access to the resources. The plan will have an additional resource element containing the entire JMS Resource deployment plan. A deployment plan that declared JMS resources using the same configuration shown in Example 7.1, “JMS Resource Group Deployment Plan” would look like this:

META-INF/geronimo-application-client.xml

<application-client xmlns=
  "http://geronimo.apache.org/xml/ns/j2ee/application-client-1.0"
  configId="MyClientConfig"
  clientConfigId="MyClient">
  ...
  <resource>
    <external-rar>
      activemq/activemq-ra/3.2.1/rar
    </external-rar>
    <connector
     xmlns="http://geronimo.apache.org/xml/ns/j2ee/connector-1.0"
     configId="MyJMSResources"
     parentId="geronimo/activemq-broker/1.0/car">
      ...
    </connector>
  </resource>
</application-client>

The important elements here are:

resource

This element contains the entire definition of the module-scoped JMS Resources

external-rar

This is formatted as a repository URI.

connector

The entire contents of the JMS Resource deployment plan should be inserted here.

In this case, when the application module is started, the JMS resources will be started as well.