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.このコンテンツは選択した言語では利用できません。
Chapter 3. Qpid JMS Client API
Warning
The Qpid JMS client API is a technical preview only, and is not supported in JBoss A-MQ 6.1.
3.1. Getting Started with AMQP リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
3.1.1. Introduction to AMQP リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
What is AMQP? リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The Advanced Message Queuing Protocol (AMQP) is an open standard messaging system, which has been designed to facilitate interoperability between messaging systems. The key features of AMQP are:
- Open standard (defined by the OASIS AMQP Technical Committee)
- Defines a wire protocol
- Defines APIs for multiple languages (C++, Java)
- Interoperability between different AMQP implementations
Warning
The Qpid JMS client API is a technical preview only, and is not supported in JBoss A-MQ 6.1.
JMS is an API リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
It is interesting to contrast the Java Message Service (JMS) with AMQP. The JMS is first and foremost an API and is designed to enable Java code to be portable between different messaging products. JMS does not describe how to implement a messaging service (although it imposes significant constraints on the messaging behaviour), nor does JMS specify any details of the wire protocol for transmitting messages. Consequently, different JMS implementations are generally not interoperable.
AMQP is a wire protocol リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
AMQP, on the other hand, does specify complete details of a wire protocol for messaging (in an open standard). Moreover, AMQP also specifies APIs in several different programming languages (for example, Java and C++). An implementation of AMQP is therefore much more constrained than a comparable JMS implementation. One of the benefits of this is that different AMQP implementations ought to be interoperable with each other.
AMQP-to-JMS requires message conversion リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
If you want to bridge from an AMQP messaging system to a JMS messaging system, the messages must be converted from AMQP format to JMS format. Usually, this involves a fairly lightweight conversion, because the message body can usually be left intact while message headers are mapped to equivalent headers.
AMQP support in JBoss A-MQ リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
AMQP support in JBoss A-MQ is based on the following main components:
- AMQP endpoint in the broker—an endpoint on the broker that supports the AMQP wire protocol and implicitly converts messages between AMQP format and JMS format (which is used inside the JBoss A-MQ broker).
- AMQP JMS client—is based on the Apache Qpid JMS client, which is compatible with the broker's AMQP endpoint.
Getting started with AMQP リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
To run a simple demonstration of AMQP in JBoss A-MQ, you need to set up the following parts of the application:
- Configure the broker to use AMQP—to enable AMQP in the broker, add an AMQP endpoint to the broker's configuration. This implicitly activates the broker's AMQP integration, ensuring that incoming messages are converted from AMQP message format to JMS message format, as required.
- Implement the AMQP clients—the AMQP clients are based on the Apache Qpid JMS client libraries.
3.1.2. Configuring the Broker for AMQP リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Configuring the broker to use AMQP is relatively straightforward in JBoss A-MQ, because the required AMQP packages are pre-installed in the container. There are essentially two main points you need to pay attention to:
- Make sure that you have appropriate user entries in the
etc/users.properties
file, so that the AMQP clients will be able to log on to the broker. - Add an AMQP endpoint to the broker (by inserting a
transportConnector
element into the broker's XML configuration).
Steps to configure the broker リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Perform the following steps to configure the broker with an AMQP endpoint:
- This example assumes that you are working with a fresh install of a standalone JBoss A-MQ broker, InstallDir.
- Define a JAAS user for the AMQP clients, so that the AMQP clients can authenticate themselves to the broker using JAAS security (security is enabled by default in the broker). Edit the
InstallDir/etc/users.properties
file and add a new user entry, as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow At this point, you can add entries for any other secure users you want. In particular, it is advisable to have at least one user with theadmin
role, so that you can log into the secure container remotely (remembering to choose a secure password for the admin user). - Add an AMQP endpoint to the broker configuration. Edit the broker configuration file,
InstallDir/etc/activemq.xml
. As shown in the following XML fragment, add the highlightedtransportConnector
element as a child of thetransportConnectors
element in the broker configuration:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - To start the broker, open a new command prompt, change directory to
InstallDir/bin
, and enter the following command:./amq
./amq
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Message conversion リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The AMQP endpoint in the broker implicitly converts incoming AMQP format messages into JMS format messages (which is the format in which messages are stored in the broker). The endpoint configuration shown here uses the default options for this conversion.
Reference リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
For full details of how to configure an AMQP endpoint in the broker, see the "Advanced Message Queueing Protocol (AMQP)" chapter from the Connection Reference. This also includes details of how to customize the message conversion from AMQP format to JMS format.
3.1.3. AMQP Example Clients リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Overview リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
This section explains how to implement two basic AMQP clients: an AMQP producer client, which sends messages to a queue on the broker; and an AMQP consumer client, which pulls messages off the queue on the broker. The clients themselves use generic JMS code to access the messaging system. The key details of the AMQP configuration are retrieved using JNDI properties.
Prerequisites リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Before building the example clients, you must install and configure the Apache Maven build tool, as described in Section 1.2, “Preparing to use Maven”.
AMQP connection URI リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
The critical piece of configuration for establishing a connection with the broker is the AMQP URI (defined as a JNDI property in the
jndi.properties
file, in this demonstration). This example uses the following AMQP URI for the clients:
amqp://amqpuser:secret@localhost/test/?brokerlist='tcp://localhost:5672'
amqp://amqpuser:secret@localhost/test/?brokerlist='tcp://localhost:5672'
The first part of the URI,
amqpuser:secret@localhost
, has the format Username:Password@ClientID
. In order to authenticate the clients successfully with the broker, it is essential that there is a corresponding JAAS user entry on the broker side.
The
brokerlist
option defines the location of the AMQP port on the broker, which is tcp://localhost:5672
for this example.
Steps to implement and run the AMQP clients リンクのコピーリンクがクリップボードにコピーされました!
リンクのコピーリンクがクリップボードにコピーされました!
Perform the following steps to implement and run an AMQP producer client and an AMQP consumer client:
- At any convenient location, create the directory,
activemq-amqp-example
, to hold the example code:mkdir activemq-amqp-example
mkdir activemq-amqp-example
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create the directory hierarchy for the example code. Change directory to
activemq-amqp-example
and run the following script at a command prompt:Copy to Clipboard Copied! Toggle word wrap Toggle overflow After executing the preceding commands, you should have the following directory structure for theactivemq-amqp-example
project:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Create a POM file for the Maven project. Using a text editor, create a new file,
activemq-amqp-example/pom.xml
, with the following contents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Define the Java implementation of an AMQP consumer class,
SimpleConsumer
. Using a text editor, create theSimpleConsumer.java
file under theactivemq-amqp-example/src/main/java/org/fusebyexample/activemq/
directory, with the following contents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Define the Java implementation of an AMQP producer class,
SimpleProducer
. Using a text editor, create theSimpleProducer.java
file under theactivemq-amqp-example/src/main/java/org/fusebyexample/activemq/
directory, with the following contents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Configure the JNDI properties for the AMQP clients. Using a text editor, create the
jndi.properties
file under theactivemq-amqp-example/src/main/resources/
directory, with the following contents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Configure the client logging with log4j. Using a text editor, create the
log4j.properties
file under theactivemq-amqp-example/src/main/resources/
directory, with the following contents:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Make sure that the broker is already configured and running with an AMQP endpoint, as described in Section 3.1.2, “Configuring the Broker for AMQP”.
- Run the AMQP producer client as follows. Open a new command prompt, change directory to the project directory,
activemq-amqp-example/
, and enter the following Maven command:mvn -P producer
mvn -P producer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow After building the code (and downloading any packages required by Maven), this target proceeds to run the producer client, which sends 100 messages to thetest.queue.simple
queue in the broker. If the producer runs successfully, you should see output like the following in the console window:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Run the AMQP consumer client as follows. Open a new command prompt, change directory to the project directory,
activemq-amqp-example/
, and enter the following Maven command:mvn -P consumer
mvn -P consumer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow After building the code, this target proceeds to run the consumer client, which reads messages from thetest.queue.simple
queue. You should see output like the following in the console window:Copy to Clipboard Copied! Toggle word wrap Toggle overflow