1.2. Install the ActiveMQ Resource Adapter
Overview
This section describes how to find, install, and configure the ActiveMQ resource adapter into a standalone instance of the JBoss Enterprise Application Platform.
A resource adapter is a kind of plug-in for a J2EE container. The J2EE standard defines the resource adapter framework, which makes it possible to expand the core J2EE container, adding new features and functionality. By installing the ActiveMQ resource adapter, you make it possible for message driven beans and servlets to communicate through an external JBoss A-MQ broker instance. The JBoss A-MQ broker can thus be used as the underlying messaging system in the container.
Resource adapter location
You can find the ActiveMQ resource adapter archive file,
activemq-rar-5.9.0.redhat-610379.rar
, at either of the following locations:
- In the following Zip archive file:
InstallDir/extras/apache-activemq-5.9.0.redhat-610379-bin.zip
After expanding the archive, the resource adapter file can be found in the following sub-directory:apache-activemq-5.9.0.redhat-610379/lib/optional
- Directly from the Red Hat JBoss Fuse Maven repository, at the following URL:
http://repo.fusesource.com/nexus/content/groups/public/org/apache/activemq/activemq-rar/
Download the.rar
archive file from the appropriately versioned sub-directory, 5.9.0.redhat-610379.
Configuration files
The following configuration files are needed for the the ActiveMQ resource adapter (when installed in a standalone instance of the JBoss Enterprise Application Platform):
InstallDir/standalone/configuration/standalone.xml
- The
standalone.xml
file is the default (bare bones) configuration for the JBoss Enterprise Application Platform container. You must edit this file to complete the installation of the ActiveMQ resource adapter.NoteIt is assumed that this file does not already configure the HornetQ messaging system (which would conflict with the ActiveMQ messaging system).
Note
JBoss Enterprise Application Platform can be figured either as a standalone container, using
standalone/configuration/standalone.xml
, or as a managed domain, using domain/configuration/domain.xml
. Throughout this section, we describe explicitly how to configure the standalone container, but it is understood that a similar approach could be used to configure a managed domain.
Steps to install the resource adapter
Perform the following steps to install the Apache ActiveMQ resource adapter into JBoss Enterprise Application Platform (assuming that you will be running the container in standalone mode):
- Extract the Apache ActiveMQ community distribution. You can find an archive of the Apache ActiveMQ distribution in the following location:
InstallDir/extras/apache-activemq-5.9.0.redhat-610379-bin.zip
Using a suitable archive utility, extract the preceding archive file to any convenient location on your filesystem. The root of the extracted directory tree is calledapache-activemq-5.9.0.redhat-610379
by default. - The ActiveMQ resource adapter archive file can now be found under the
/lib/optional
sub-directory of the archive extracted in the previous step. Make a copy of the ActiveMQ resource adapter archive file, omitting the version number in the filename. For example, on a UNIX or Linux platform, you can rename theactivemq-rar-5.9.0.redhat-610379.rar
archive file as follows:cd apache-activemq-5.9.0.redhat-610379/lib/optional cp activemq-rar-5.9.0.redhat-610379.rar activemq-rar.rar
NoteRenaming the resource adapter archive in this way is not strictly necessary. But because the resource adapter file name appears in the resource adapter configuration, using a versionless filename makes it easier to upgrade the resource adapter at a later date. - Install the ActiveMQ resource adapter by copying the resource adapter archive,
activemq-rar.rar
, to the relevant JBoss Enterprise Application Platform deployment directory. For example, on a UNIX or Linux platform, you could copy the resource adapter archive to a standalone JBoss Enterprise Application Platform as follows:cp activemq-rar.rar EAPInstallDir/standalone/deployments/
- Add the requisite resource adapter configuration to the
urn:jboss:domain:resource-adapters:1.1
subsystem in the JBoss Enterprise Application Platform configuration, as follows.Open theEAPInstallDir/standalone/configuration/standalone.xml
file using a text editor and paste theresource-adapter
element from Example 1.1, “ActiveMQ Resource Adapter Configuration in standalone.xml” into theurn:jboss:domain:resource-adapters:1.1
subsystem, as a child of theresource-adapters
element.Example 1.1. ActiveMQ Resource Adapter Configuration in standalone.xml
<server xmlns="urn:jboss:domain:1.4"> ... <profile> ... <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1"> <resource-adapters> <resource-adapter id="activemq-rar.rar"> <archive> activemq-rar.rar </archive> <transaction-support>XATransaction</transaction-support> <config-property name="UserName"> defaultUser </config-property> <config-property name="Password"> defaultPassword </config-property> <config-property name="ServerUrl"> tcp://localhost:61616?jms.rmIdFromConnectionId=true </config-property> <connection-definitions> <connection-definition class-name="org.apache.activemq.ra.ActiveMQManagedConnectionFactory" jndi-name="java:/ConnectionFactory" enabled="true" pool-name="ConnectionFactory"> <xa-pool> <min-pool-size>1</min-pool-size> <max-pool-size>20</max-pool-size> <prefill>false</prefill> <is-same-rm-override>false</is-same-rm-override> </xa-pool> <recovery> <recover-credential> <user-name>defaultUser</user-name> <password>defaultPassword</password> </recover-credential> </recovery> </connection-definition> </connection-definitions> <admin-objects> <admin-object class-name="org.apache.activemq.command.ActiveMQQueue" jndi-name="java:/queue/HELLOWORLDMDBQueue" use-java-context="true" pool-name="HELLOWORLDMDBQueue"> <config-property name="PhysicalName"> HELLOWORLDMDBQueue </config-property> </admin-object> <admin-object class-name="org.apache.activemq.command.ActiveMQTopic" jndi-name="java:/topic/HELLOWORLDMDBTopic" use-java-context="true" pool-name="HELLOWORLDMDBTopic"> <config-property name="PhysicalName"> HELLOWORLDMDBTopic </config-property> </admin-object> </admin-objects> </resource-adapter> ... </resource-adapters> </subsystem> ... </profile> ... </server>
If your resource adapter archive filename differs fromactivemq-rar.rar
, you must change the content of thearchive
element in the preceding configuration to match the name of your archive file.The values of theUserName
andPassword
configuration properties must be chosen to match the credentials of a valid user in the external broker.You might need to change the value of theServerUrl
configuration property to match the actual hostname and port exposed by the external broker.ImportantIn order to ensure that JMS transactions are integrated correctly, it is essential to include thejms.rmIdFromConnectionId=true
option setting on theServerUrl
configuration property and to include the<is-same-rm-override>false</is-same-rm-override>
setting in thexa-pool
element, as shown above.NoteThe JMS administrative objects defined in theadmin-objects
element do not need to be defined yet. They serve as examples to show how you can define administrative objects for the ActiveMQ resource adapter (they are used later in the message-driven bean demonstration). - Add the requisite message driven bean configuration to the
urn:jboss:domain:ejb3:1.4
subsystem in the JBoss Enterprise Application Platform configuration.Open theEAPInstallDir/standalone/configuration/standalone.xml
file using a text editor and paste themdb
element from Example 1.2, “Message Driven Bean Configuration in standalone.xml” into theurn:jboss:domain:ejb3:1.4
subsystem.Example 1.2. Message Driven Bean Configuration in standalone.xml
<server xmlns="urn:jboss:domain:1.4"> ... <profile> ... <subsystem xmlns="urn:jboss:domain:ejb3:1.4"> ... <mdb> <resource-adapter-ref resource-adapter-name="activemq-rar.rar"/> <bean-instance-pool-ref pool-name="mdb-strict-max-pool"/> </mdb> <pools> <bean-instance-pools> <strict-max-pool name="slsb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/> <strict-max-pool name="mdb-strict-max-pool" max-pool-size="20" instance-acquisition-timeout="5" instance-acquisition-timeout-unit="MINUTES"/> </bean-instance-pools> </pools> ... </subsystem> ... </profile> ... </server>
- Before starting the broker, check the broker configuration to make sure that there are valid user credentials defined in the broker's
InstallDir/etc/users.properties
file. For example, to match theUserName
andPassword
credentials configured in Example 1.1, “ActiveMQ Resource Adapter Configuration in standalone.xml”, theusers.properties
file should contain an entry like the following:defaultUser=defaultPassword,admin
- Start the external A-MQ broker. For example, on a UNIX or Linux platform, you can start the JBoss A-MQ broker instance as follows:
cd InstallDir/bin ./amq
- Start the standalone instance of JBoss Enterprise Application Platform. For example, on a UNIX or Linux platform, you can start the standalone instance as follows:
cd EAPInstallDir/bin ./standalone.sh
Resource adapter configuration
In the configuration shown in Example 1.1, “ActiveMQ Resource Adapter Configuration in standalone.xml”, you use the
config-property
element to set resource adapter properties. The ActiveMQ resource adapter supports the following basic properties:
UserName
- (Optional) Specifies the client username when connecting to the JBoss A-MQ broker (not required in this example, because the JBoss A-MQ broker configuration does not enable authentication).
Password
- (Optional) Specifies the client password when connecting to the JBoss A-MQ broker (not required in this example, because the JBoss A-MQ broker configuration does not enable authentication).
ServerUrl
- Specifies the URL used to connect to the JBoss A-MQ broker instance. This value must match one of the endpoints specified by a
transportConnector
element in the JBoss A-MQ broker configuration. BrokerXmlConfig
- (Optional) Specifies the location of an embedded broker's XML configuration file. To specify a location on the file system, use the format,
xbean:file://AbsolutePath
, where the path,AbsolutePath
, should be specified as an absolute pathname. UseInboundSession
- (Optional) Sets a flag that specifies whether outbound connections should reuse the inbound connection's session for sending messages (useful for connections going through a firewall). Defaults to
false
. Clientid
- (Optional) Specifies a JMS client ID, which the resource adapter uses for the connection from the JBoss Enterprise Application Platform container.
JBoss A-MQ broker configuration
Most of the options for customizing the ActiveMQ resource adapter are provided by the JBoss A-MQ broker configuration file, at the following location:
InstallDir/etc/activemq.xml
This configuration file supports a huge range of features and settings which are beyond the scope of this guide. To learn more about JBoss A-MQ broker configuration, see the following guides from the Red Hat JBoss A-MQ documentation library:
- Configuring Broker Persistence
- Tuning Guide
- Security Guide
- XML Configuration Reference