Red Hat AMQ 6
As of February 2025, Red Hat is no longer supporting Red Hat AMQ 6. If you are using AMQ 6, please upgrade: Migrating to AMQ 7.このコンテンツは選択した言語では利用できません。
Integrating with JBoss Enterprise Application Platform
Red Hat JBoss A-MQ
Installing the ActiveMQ resource adapter into the JBoss Enterprise Application Platform container
Version 6.3
Copyright © 2011-2017 Red Hat, Inc. and/or its affiliates.
23 Oct 2020
Abstract
This guide describes how to integrate the ActiveMQ resource adapter into a JBoss Enterprise Application Platform and how to run an example with Message Driven Beans.
Chapter 1. Deploying the Apache ActiveMQ Resource Adapter リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Abstract
This chapter explains how to install the Apache ActiveMQ resource adapter into JBoss EAP and how to integrate ActiveMQ messaging into your applications, taking the
helloworld-mdb demonstration as an example.
1.1. Supported Web Server Platforms リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The following Web server platforms are supported by JBoss A-MQ 6.3:
- JBoss Enterprise Application Platform (JBoss EAP)
Supported product versions リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To see which versions of JBoss EAP are supported with JBoss A-MQ 6.3, please consult the Red Hat JBoss A-MQ Supported Configurations page.
Note
AMQP 1.0 is not a supported protocol for the JBoss A-MQ JCA connector (Apache ActiveMQ resource adapter). OpenWire is the only wire protocol supported by the JCA connector / resource adapter.
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 EAP.
A resource adapter is a kind of plug-in for a Java EE container. The Java EE standard defines the resource adapter framework, which makes it possible to expand the core Java EE 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.
Note
Running an embedded ActiveMQ broker in JBoss EAP is not supported. The use of the resource adapter is restricted to connect to external broker instances only.
Resource adapter location リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
You can find the ActiveMQ resource adapter archive file,
activemq-rar-5.11.0.redhat-630187.rar, at either of the following locations:
- In the following Zip archive file:
InstallDir/extras/apache-activemq-5.11.0.redhat-630187-bin.zip
InstallDir/extras/apache-activemq-5.11.0.redhat-630187-bin.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow After expanding the archive, the resource adapter file can be found in the following sub-directory:apache-activemq-5.11.0.redhat-630187/lib/optional
apache-activemq-5.11.0.redhat-630187/lib/optionalCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Directly from the Red Hat JBoss Fuse Maven repository, at the following URL:
https://maven.repository.redhat.com/ga/org/apache/activemq/activemq-rar/
https://maven.repository.redhat.com/ga/org/apache/activemq/activemq-rar/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Download the.rararchive file from the appropriately versioned sub-directory, 5.11.0.redhat-630187.
Configuration files リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The following configuration files are needed for the the ActiveMQ resource adapter (when installed in a standalone instance of the JBoss EAP):
InstallDir/standalone/configuration/standalone-full.xml- The
standalone-full.xmlfile is the default (bare bones) configuration for the JBoss EAP 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 EAP can be figured either as a standalone container, using
standalone/configuration/standalone-full.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 EAP (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.11.0.redhat-630187-bin.zip
InstallDir/extras/apache-activemq-5.11.0.redhat-630187-bin.zipCopy to Clipboard Copied! Toggle word wrap Toggle overflow Using a suitable archive utility, extract the archive file to a convenient location on your filesystem. The root of the extracted directory tree is calledapache-activemq-5.11.0.redhat-630187by default. - The ActiveMQ resource adapter archive file can now be found under the
/lib/optionalsub-directory of the extracted archive.If you need to use the ActiveMQXAConnectionFactory, you need to add extra details to the ActiveMQ resource adapter file at this point. Extract the resource adapter archive,activemq-rar-5.11.0.redhat-630187.rarto a work space. In the expanded resource adapter archive, editMETA_INF/ra.xml.Add the following entry to the adminobjects in thera.xmlfile.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Zip up the resource adapter archive, and save it to a temporary location. - Rename the updated and saved resource adapter archive file. The new file name should be the same as the original name, but without the version number in the filename. For example, on a UNIX or Linux platform, you can rename the
activemq-rar-5.11.0.redhat-630187.rararchive file toactivemq-rar.rarNoteRenaming 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 EAP 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/
cp activemq-rar.rar EAPInstallDir/standalone/deployments/Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add the requisite resource adapter configuration to the
urn:jboss:domain:resource-adapters:1.1subsystem in the JBoss EAP configuration, as follows.Open theEAPInstallDir/standalone/configuration/standalone-full.xmlfile using a text editor and paste theresource-adapterelement from Example 1.1, “ActiveMQ Resource Adapter Configuration in standalone-full.xml” into theurn:jboss:domain:resource-adapters:1.1subsystem, as a child of theresource-adapterselement.Example 1.1. ActiveMQ Resource Adapter Configuration in standalone-full.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you need to use the ActiveMQXAConnectionFactory, you must also add the following information to theadmin-objectsection ofstandalone-full.xml.Copy to Clipboard Copied! Toggle word wrap Toggle overflow If your resource adapter archive filename differs fromactivemq-rar.rar, you must change the content of thearchiveelement in the preceding configuration to match the name of your archive file.The values of theUserNameandPasswordconfiguration properties must be chosen to match the credentials of a valid user in the external broker.You might need to change the value of theServerUrlconfiguration 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=trueoption setting on theServerUrlconfiguration property and to include the<is-same-rm-override>false</is-same-rm-override>setting in thexa-poolelement, as shown above.NoteThe JMS administrative objects defined in theadmin-objectselement 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.5subsystem in the JBoss EAP configuration (where the subsystem version might vary, depending on which version of JBoss EAP you are using).Open theEAPInstallDir/standalone/configuration/standalone-full.xmlfile using a text editor and paste themdbelement from Example 1.2, “Message Driven Bean Configuration in standalone-full.xml” into theurn:jboss:domain:ejb3:1.5subsystem.Example 1.2. Message Driven Bean Configuration in standalone-full.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 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.propertiesfile. For example, to match theUserNameandPasswordcredentials configured in Example 1.1, “ActiveMQ Resource Adapter Configuration in standalone-full.xml”, theusers.propertiesfile should contain an entry like the following:defaultUser=defaultPassword,admin
defaultUser=defaultPassword,adminCopy to Clipboard Copied! Toggle word wrap Toggle overflow - 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
cd InstallDir/bin ./amqCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Start the standalone instance of JBoss EAP. For example, on a UNIX or Linux platform, you can start the standalone instance as follows:
cd EAPInstallDir/bin ./standalone-full.sh
cd EAPInstallDir/bin ./standalone-full.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Steps to secure the resource adapter with SSL/TLS リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The following steps describe how to modify the configuration of the ActiveMQ resource adapter to enable it to connect to a broker that is secured by an SSL/TLS protocol:
- It is assumed that the remote broker is already configured with an SSL/TLS endpoint. For details of how to configure an OpenWire/SSL endpoint on the broker, see section "Setting Security Context for the Openwire/SSL Protocol" in "Security Guide".
- Open the
EAPInstallDir/standalone/configuration/standalone-full.xmlfile using a text editor and modify theServerUrlproperty setting of theactivemq-rar.rarresource adapter to point at the remote broker's OpenWire/SSL endpoint. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Where thesslscheme selects the OpenWire/SSL protocol andlocalhost:61617should be customized to the host and port value of the remote broker's secure endpoint. - Specify the location and password for a trust store file, which will be used to verify the broker's certificate during the SSL/TLS handshake. Add the following property settings to the
activemq-rar.rarresource adapter configuration and theorg.apache.activemq.ra.ActiveMQManagedConnectionFactoryconnection definition configuration. Customize the settings as appropriate:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - (Optional) If the remote broker has also been configured to require a client certificate, then it is necessary to configure the ActiveMQ resource adapter with a key store file containing a public/private key pair. In this case, you need to add the following property settings to the
activemq-rar.rarresource adapter configuration and theorg.apache.activemq.ra.ActiveMQManagedConnectionFactoryconnection definition configuration. Customize the settings as appropriate:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIn order for the resource adapter's certificate (the public key from the key store) to be accepted by the broker it is necessary for this certificate to be trusted by the broker. This can be achieved either by adding the resource adapter's certificate to the broker's trust store or by arranging to have the resource adapter's certificate signed by one of the certificates in the broker's trust store. For more background information on certificate signing and trust, see appendix "Managing Certificates" in "Security Guide".
Resource adapter configuration リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
In the configuration shown in Example 1.1, “ActiveMQ Resource Adapter Configuration in standalone-full.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
transportConnectorelement 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.NoteThis property is used to run an embedded ActiveMQ broker within resource adapter. Please note that running an embedded ActiveMQ broker in JBoss EAP is currently not supported. 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 EAP container.
TrustStore- Specifies the location of a trust store file, using an absolute pathname. The trust store is required, if the ActiveMQ resource adapter connects to the broker using an SSL/TLS protocol. The trust store is provided in the form of a Java keystore file, which can contain one or multiple trusted certificates.
TrustStorePassword- Specifies the password for accessing the trust store file.
KeyStore- Specifies the location of a key store file, using an absolute pathname. The key store is required, if the ActiveMQ resource adapter connects to the broker using and SSL/TLS protocol and the remote broker is also configured to require a client certificate. The key store is provided in the form of a Java keystore file, which contains a single public/private key pair.
KeyStorePassword- Specifies the password that is used both for accessing the key store file and for unencrypting the private key entry (it is a common convention to use the same password for locking the keystore file and for encrypting the private key entry).
JBoss A-MQ broker configuration リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Most of the options for customizing the ActiveMQ broker are provided by the JBoss A-MQ broker configuration file, at the following location:
InstallDir/etc/activemq.xml
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
1.3. Integrating with an ActiveMQ Failover Cluster リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
This section describes how to configure the ActiveMQ resource adapter to connect to an ActiveMQ failover cluster (for example, a high-availability master/slave cluster). For details about how to set up and configure such a cluster, see "Fault Tolerant Messaging".
Failover URL リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To connect to a cluster of JBoss A-MQ brokers (for example, a master/slave pair of brokers), you need to configure the
ServerUrl configuration property with a failover URL, which lists the available endpoints in the cluster. The general form of the failover URL you should use is as follows:
failover:(uri1,...,uriN)?maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
failover:(uri1,...,uriN)?maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
Note
It is important to set the options as shown, in order to ensure a clean cutover when the master fails in a master/slave high-availability cluster. You do not want a failover client to attempt reconnection to the same endpoint. The client should always try the next URI in the failover list.
Sample scenario リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Consider the scenario where a broker running on host
amqhostA and a broker running on host amqhostB are configured to run as a high-availability master/slave cluster. In this scenario, the brokers expose the following TCP endpoints:
tcp://amqhostA:61616 tcp://amqhostB:61616
tcp://amqhostA:61616
tcp://amqhostB:61616
To connect to this cluster, the resource adapter should be configured with the following failover URL:
failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
When setting the URL in an XML file, you must remember to escape the
& symbol as & giving the URL:
failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
failover:(tcp://amqhostA:61616,tcp://amqhostB:61616)?jms.rmIdFromConnectionId=true&maxReconnectAttempts=0&reconnectSupported=false&updateURIsSupported=false&priorityBackup=false
Configuring the ActiveMQ resource adapter for failover リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To configure the ActiveMQ resource adapter to connect to an ActiveMQ failover cluster, you must modify the following configuration settings:
- Set the
ServerUrlconfiguration property to a correctly configured failover URL, - Set the
UseInboundSessionconfiguration property totruefor inbound connections (set as the direct child of theresource-adapterelement), and - Set the
UseInboundSessionconfiguration property tofalsefor the connection factories (set as the child of aconnection-definitionelement).
Open the
EAPInstallDir/standalone/configuration/standalone-full.xml file using a text editor, search for the urn:jboss:domain:resource-adapters:1.1 subsystem, and modify the ServerUrl property and the UseInboundSession property as shown in Example 1.3, “ActiveMQ Resource Adapter Configuration for Failover”. You will need to customize the value of the failover URL, as appropriate, to match the configuration of your broker cluster.
Example 1.3. ActiveMQ Resource Adapter Configuration for Failover
1.4. Install JBoss AS Quickstarts リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The JBoss AS Quickstart examples consists of a collection of demonstrations that illustrate features of the JBoss EAP. The installation consists of the following parts:
- JBoss EAP Maven repository—an offline Maven repository for JBoss EAP, which contains the dependencies required by the quickstart examples.
- JBoss AS Quickstart examples—the quickstart examples themselves.
Prerequisites リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To download, install, and build the JBoss AS Quickstart examples, you need the following prerequisites:
- Subscription—you must have a Red Hat subscription that includes support for the JBoss EAP product (or ask Red Hat support for access as part of an evaluation).
- Maven installation—you must have Apache Maven installed and the version must be 3.3 or later. You can get the latest copy of Maven from the Maven download page.
- Internet access—Maven is a distributed build system, which downloads packages from the Internet on the fly, whenever they are needed during a build. Consequently, you must have access to the Internet while performing a Maven build.
JBoss AS Quickstarts download location リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
You can download the JBoss AS Quickstart examples from the Quickstarts download page on the Red Hat Customer Portal site. Click the following link to download the
jboss-eap-6.4.0-quickstarts.zip file:
Note
After following this link, you will be prompted to log on to the Red Hat customer access portal. If you do not have a subscription for JBoss EAP you will not be able to access this download, however.
Maven repository download location リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The JBoss EAP Maven repository is required in order to run the quickstart examples.
You can download the Maven repository from the Maven Repository download page on the Red Hat Customer Portal site. Click the following link to download the
jboss-eap-6.4.0-maven-repository.zip file:
Steps to install JBoss AS Quickstarts リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To install the JBoss AS Quickstart examples, perform the following steps:
- Download the
jboss-eap-6.4.0-quickstarts.zipfile from the customer portal site. Use an archive utility to unzip the downloaded file at a convenient location on your filesystem,QuickInstallDir. - Download the
jboss-eap-6.4.0-maven-repository.zipfile from the customer portal site. Use an archive utility to unzip the downloaded file at a convenient location on your filesystem,MvnRepoInstallDir.NoteIt is essential to download and install the Maven repository on your local machine. The quickstart examples require Maven artifacts that are not available from any public repositories online. You will not be able to build the quickstart examples unless you download, install, and configure the Maven repository. - Configure Maven to use the downloaded Maven repository by editing your local repository's
settings.xmlfile (usually located at~/.m2/settings.xmlon Linux and UNIX systems, or atC:\Documents and Settings\Username\.m2\settings.xmlon Windows). Open thesettings.xmlfile with a text editor and add the following profiles:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteAlternatively, there is a sample settings file provided atMvnRepoInstallDir/example-settings.xmlin the downloaded Maven repository, which you can use as a template for defining yoursettings.xmlfile. - Replace all occurrences of
file:///path/to/jboss-eap-6.4.0.GA-maven-repositoryin thesettings.xmlfile with the actual location of the Maven repository on your filesystem,MvnRepoInstallDir.
Test the installation リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To test the installation of the quickstart examples, try to build the
helloworld-mdb example using Maven. Open a new command window, change directory to QuickInstallDir/helloworld-mdb, and enter the following command:
mvn clean package
mvn clean package
If the project builds successfully, you should see a
BUILD SUCCESS status and the generated jboss-as-helloworld-mdb.war package will be found under the QuickInstallDir/target directory.
If the project does not build successfully, make sure that you have access to the Internet and check that the Maven
settings.xml file is correctly configured.
1.5. Build and Deploy the helloworld-mdb Example リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
In this tutorial, you will customize the
helloworld-mdb quickstart example so that it works with the ActiveMQ resource adapter. You can then build and deploy the helloworld-mdb example into a standalone instance of JBoss Enterprise Application Platform (which already has an ActiveMQ resource adapter installed).
The
helloworld-mdb example illustrates two kinds of integration with messaging: integration of message-driven beans; and integration of a servlet (which gets access to a JMS queue and a JMS topic using the standard JMS administered objects mechanism).
Prerequisites リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The following prerequisites must be satisfied, before you can build and deploy the
helloworld-mdb example:
- The ActiveMQ resource adapter is installed in JBoss EAP (as described in Section 1.2, “Install the ActiveMQ Resource Adapter”), and the installation has been verified.
- The JBoss EAP Maven repository and the JBoss AS Quickstart examples have been installed (as described in Section 1.4, “Install JBoss AS Quickstarts”).
- You have Internet access (for the Maven build).
Customizations リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The version of the
helloworld-mdb demonstration provided in the quickstarts distribution is integrated with the HornetQ messaging platform by default. To refactor the demonstration so that it integrates with Apache ActiveMQ, it is necessary to customize the following aspects of the helloworld-mdb code:
- Delete the HornetQ XML configuration file (located in
helloworld-mdb/src/main/webapp/WEB-INF/hornetq-jms.xml). - In
HelloWorldQueueMDB.java, customize the annotations on the message driven bean to integrate with the ActiveMQ resource adapter. - In
HelloWorldTopicMDB.java, customize the annotations on the message driven bean to integrate with the ActiveMQ resource adapter. - Add additional Maven dependencies.
These customizations are described in more detail in the rest of this section.
Steps to build and deploy the example リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To build and deploy the quickstart
helloworld-mdb example, perform the following steps:
- Delete the following HornetQ XML configuration file from the
helloworld-mdbproject:helloworld-mdb/src/main/webapp/WEB-INF/hornetq-jms.xml
helloworld-mdb/src/main/webapp/WEB-INF/hornetq-jms.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Edit the annotations on the
HelloWorldQueueMDBmessage driven bean class, so that it integrates with the ActiveMQ resource adapter (instead of HornetQ). Edit theHelloWorldQueueMDB.javafile at the following location:helloworld-mdb/src/main/java/org/jboss/as/quickstarts/mdb/HelloWorldQueueMDB.java
helloworld-mdb/src/main/java/org/jboss/as/quickstarts/mdb/HelloWorldQueueMDB.javaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Open theHelloWorldQueueMDB.javafile using a text editor and make the modifications highlighted in the following extract:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Where the following changes are made to the code:- The
@ResourceAdapterannotation explicitly associates the message driven bean with the ActiveMQ resource adapter. You must include this annotation, if you want to use the ActiveMQ resource adapter. - You need to add an
importstatement for the@ResourceAdapterannotation. - The value of the
destinationproperty is changed toHELLOWORLDMDBQueue, which is the physical name of the corresponding ActiveMQ queue that this message driven bean subscribes to. The physical name of the queue is the queue identifier used by the JBoss A-MQ broker.NoteYou must specify the queue's physical name here. In contrast to the case of HornetQ, the ActiveMQ messaging integration does not allow you to use a JNDI name for thedestinationvalue.
- Edit the annotations on the
HelloWorldTopicMDBmessage driven bean class, so that it integrates with the ActiveMQ resource adapter (instead of HornetQ). Edit theHelloWorldTopicMDB.javafile at the following location:helloworld-mdb/src/main/java/org/jboss/as/quickstarts/mdb/HelloWorldTopicMDB.java
helloworld-mdb/src/main/java/org/jboss/as/quickstarts/mdb/HelloWorldTopicMDB.javaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Open theHelloWorldTopicMDB.javafile using a text editor and make the modifications highlighted in the following extract:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add the Maven dependency for the
jboss-ejb3-ext-apiartifact, which is needed for the@ResourceAdapterannotation. Open thehelloworld-mdb/pom.xmlfile using a text editor and add the followingdependencyelement as a child of thedependencieselement in the POM file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Theprovidedscope value implies there is no need to embed thejboss-ejb3-ext-apiJAR file in the generated WAR, because this library is already provided by the JBoss EAP container.NoteIf you ever need to update the version of thejboss-ejb3-ext-apiartifact, you can discover which version to use by drilling down to theorg/jboss/ejb3/jboss-ejb3-ext-apisubdirectory of the Maven repository you downloaded and installed in Section 1.4, “Install JBoss AS Quickstarts”. - Build the
helloworld-mdbexample as follows. Open a new command prompt, change directory to thehelloworld-mdbdirectory, and enter the following Maven command:mvn clean package
mvn clean packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow If the build is successful, you should find thejboss-as-helloworld-mdb.warWAR file in thehelloworld-mdb/targetdirectory. - If you have not already done so, register the administered objects for the queues and topics used by the example, by editing the JBoss EAP configuration.In your JBoss EAP installation, open the
standalone/configuration/standalone-full.xmlconfiguration file with a text editor, and add the following highlighted administered objects to theactivemq-rar.rarresource adapter:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Where the preceding configuration adds the following entries to the JNDI registry:java:/queue/HELLOWORLDMDBQueue- References a
javax.jms.Queueobject that connects to theHELLOWORLDMDBQueueActiveMQ queue (where the queue name on the JBoss A-MQ broker is specified by thePhysicalNameconfig property). java:/queue/HELLOWORLDMDBTopic- References a
javax.jms.Topicobject that connects to theHELLOWORLDMDBTopicActiveMQ topic (where the topic name on the JBoss A-MQ broker is specified by thePhysicalNameconfig property).
In thehelloworld-mdbexample, these administered objects are accessed by the servlet class,HelloWorldMDBServletClient(but not by the message driven bean classes). For example, theHelloWorldMDBServletClientclass injects these JNDI entries, using the@Resourceannotation, as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Deploy the
helloworld-mdbexample to the running Web server. Manually copy thejboss-as-helloworld-mdb.warWAR file from thehelloworld-mdb/targetdirectory to the Web server's deployment directory,standalone/deployments.
Access the helloworld-mdb service リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
You can now test the
helloworld-mdb service, as follows:
- If you have not already started the JBoss EAP standalone container, do so by entering the following commands at the command line:
cd EAPInstallDir/bin ./standalone.sh
cd EAPInstallDir/bin ./standalone.shCopy to Clipboard Copied! Toggle word wrap Toggle overflow - You should now be able to access the
helloworld-mdbservice from your browser, by navigating to the following URL:http://localhost:8080/jboss-helloworld-mdb/HelloWorldMDBServletClient
http://localhost:8080/jboss-helloworld-mdb/HelloWorldMDBServletClientCopy to Clipboard Copied! Toggle word wrap Toggle overflow When you navigate to the preceding URL, the servlet sends five messages to theHelloWorldQueueMDBmessage-driven bean. If you look at the container console window, you should see some output like the following:14:41:20,739 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 7) Received Message from queue: This is message 5 14:41:20,739 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 5) Received Message from queue: This is message 3 14:41:20,739 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 4) Received Message from queue: This is message 2 14:41:20,741 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 6) Received Message from queue: This is message 4 14:41:20,742 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 3) Received Message from queue: This is message 1
14:41:20,739 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 7) Received Message from queue: This is message 5 14:41:20,739 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 5) Received Message from queue: This is message 3 14:41:20,739 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 4) Received Message from queue: This is message 2 14:41:20,741 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 6) Received Message from queue: This is message 4 14:41:20,742 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldQueueMDB] (default-threads - 3) Received Message from queue: This is message 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow These console messages are written by theHelloWorldQueueMDBmessage-driven bean, thus demonstrating that the messages have successfully propagated from the servlet, through the JBoss A-MQ broker, to the message-driven bean. - To send messages to the
HelloWorldTopicMDBmessage-driven bean, navigate to the following URL:http://localhost:8080/jboss-helloworld-mdb/HelloWorldMDBServletClient?topic
http://localhost:8080/jboss-helloworld-mdb/HelloWorldMDBServletClient?topicCopy to Clipboard Copied! Toggle word wrap Toggle overflow When you navigate to the preceding URL, the servlet sends five messages to theHelloWorldTopicMDBmessage-driven bean. If you look at the container console window, you should see some output like the following:14:53:02,464 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 9) Received Message from topic: This is message 2 14:53:02,466 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 10) Received Message from topic: This is message 3 14:53:02,468 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 8) Received Message from topic: This is message 1 14:53:02,471 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 11) Received Message from topic: This is message 4 14:53:02,472 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 12) Received Message from topic: This is message 5
14:53:02,464 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 9) Received Message from topic: This is message 2 14:53:02,466 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 10) Received Message from topic: This is message 3 14:53:02,468 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 8) Received Message from topic: This is message 1 14:53:02,471 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 11) Received Message from topic: This is message 4 14:53:02,472 INFO [class org.jboss.as.quickstarts.mdb.HelloWorldTopicMDB] (default-threads - 12) Received Message from topic: This is message 5Copy to Clipboard Copied! Toggle word wrap Toggle overflow These console messages are written by theHelloWorldTopicMDBmessage-driven bean, thus demonstrating that the messages have successfully propagated from the servlet, through the JBoss A-MQ broker, to the message-driven bean.
Legal Notice リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Trademark Disclaimer
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Apache, ServiceMix, Camel, CXF, and ActiveMQ are trademarks of Apache Software Foundation. Any other names contained herein may be trademarks of their respective owners.