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.此内容没有您所选择的语言版本。
3.5. C++ AMQP 1.0 Client API
C++ AMQP 1.0 Client API is based on the Apache Qpid C++ AMQP 1.0 Client API.
Note
This is an initial version of documentation for the C++ client. Regular updates and enhancements of the documentation can be expected after the GA release of Fuse 6.2.0
3.5.1. Getting Started with C++ AMQP 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Introduction to C++ AMQP 1.0 Client API 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
C++ Messaging Service (CMS) API is used for interfacing with Message Brokers such as A-MQ. A-MQ-C++ is a client library that uses A-MQ as a message broker for clients to communicate. The architecture of CMS supports pluggable transports and wire formats. At present, OpenWire and Stomp protocols are supported over TCP and SSL. Failover Transport is also supported for reliable client operation. In addition to CMS, A-MQ-C++ provides a set of classes that support platform independent constructs such as threading, I/O, sockets.
CMS and JMS are similar with some minor differences, mostly CMS adheres to the JMS specifications. To know more about CMS API, see CMS API Overview
Downloading A-MQ C++ Client 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
You can Download A-MQ C++ client from the Red Hat Customer Portal C++ Client
3.5.2. C++ Example Clients 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
A Simple Messaging Program in C++ 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
The following program shows how to create a simple Asynchronous consumer that can receive TextMessage objects from an A-MQ broker.
In this example, we create ConnectionFactory object. This object is used to create a CMS Connection using the ConnectionFactory. A Connection is the Object that manages the client's connection to the Provider. After creating a connection, the client creates a CMS Session to create message producers and consumers.
Example 3.13. Simple Asynchronous Consumer
- 1
- The constructor of the
SimpleAsyncConsumer
class. This constructor allows the user to create an instance of the class that connects to a particular broker and destination. It also identifies the destination as a Queue or a Topic - 2
- The
runConsumer
method creates a Connection to the broker and start a new Session configured with the configured Acknowledgment mode. Once a Session is created a new Consumer can then be created and attached to the configured Destination. To listen asynchronously for new messages theSimpleAsyncConsumer
inherits fromcms::MessageListener
so that it can register itself as a Message Listener with theMessageConsumer
created inrunConsumer
method. - 3
- All the messages received by the application are dispatched to the
onMessage
method and if the message is a TextMessage its contents are printed on the screen.
Example 3.14. A simple Asynchronous producer
- 1
- The
SimpleProducer
class exposes a similar interface to the consumer example Example 3.13, “Simple Asynchronous Consumer”. The constructor creates an instance with the configuration options for the broker and destination and the number of messages to be send to the configured destination. - 2
- The
run
method publishes the specified number of messages. Once the run method completes, the client can close theSimpleProducer
application by calling theclose()
method, which cleans up the allocated CMS resource and exits the application.
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
This section describes how to enable SSL/TLS security for the AMQP protocol, where the connection is made between:
- A-MQ broker, deployed on a RHEL host, and
- Qpid C++ client, deployed on a RHEL host.
Configuring SSL/TLS for the broker on RHEL 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Follow these steps to enable SSL/TLS security for the AMQP endpoint of a broker running on RHEL:
- Create a certificate,
test.jks
, for testing purposes:keytool -genkey -alias jboss -keyalg RSA -keystore test.jks -storepass password -dname "CN=test,O=test"
keytool -genkey -alias jboss -keyalg RSA -keystore test.jks -storepass password -dname "CN=test,O=test"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Store the new certificate file,test.jks
, in the broker's${A-MQ_HOME}/etc/
directory. - Configure the broker to use the
test.jks
certificate and enable SSL/TLS on the broker's AMQP connector by editing the${A-MQ_HOME}/etc/activemq.xml
file as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor more details about the broker configuration, see Securing a Broker using SSL/TLS. - Export the certificate in a format that can be used by the Qpid C++ client running on RHEL (in the next step):
keytool -exportcert -rfc -keystore test.jks -storepass password -alias jboss -file ./sample_cert.cer
keytool -exportcert -rfc -keystore test.jks -storepass password -alias jboss -file ./sample_cert.cer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You need to copy the resultingsample_cert.cer
file to the client RHEL machine. One way of doing this is to use the secure copy command,scp
, to copy thesample_cert.cer
file securely across the network:scp sample_cert.cer ${USER_NAME}@0.0.0.0:${CLIENT_TARGET_PATH}
scp sample_cert.cer ${USER_NAME}@0.0.0.0:${CLIENT_TARGET_PATH}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Where${USER_NAME}
is the relevant user name on the client RHEL machine and${CLIENT_TARGET_PATH}
is the location on the remote file system where you want to copy the certificate.
Configuring SSL/TLS on the client side 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Follow these steps to enable SSL/TLS security on a Qpid C++ client deployed on a remote RHEL machine:
- Install the Qpid C++ client packages, along with the
qpid-send
andqpid-receive
packages for testing:yum install qpid-cpp-client yum install log4cpp yum install qpid-cpp-client-devel yum isntall log4cpp-devel
yum install qpid-cpp-client yum install log4cpp yum install qpid-cpp-client-devel yum isntall log4cpp-devel
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - The
keytool
command is needed for generating self-signed certificates. If it is not already available, install OpenJDK as follows:yum install java-1.8.0-openjdk-headless-1.8.0.51-0.b16.el6_6.x86_64
yum install java-1.8.0-openjdk-headless-1.8.0.51-0.b16.el6_6.x86_64
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Set up the client environment, using the NSS (Network Security Services) database to install the
sample_cert.cer
certificate:mkdir -p ~/nssdb certutil -A -n selfsigned -d ~/nssdb -t "CT,," -i ./sample_cert.cer
mkdir -p ~/nssdb certutil -A -n selfsigned -d ~/nssdb -t "CT,," -i ./sample_cert.cer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Set the following environment variables:
export QPID_SSL_CERT_DB=${YOUR_WORK_PATH}/nssdb
export QPID_SSL_CERT_DB=${YOUR_WORK_PATH}/nssdb
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Test the new configuration using the
qpid-send
command and theqpid-receive
command:qpid-send -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}" --content-string "hello world" qpid-receive -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}"
qpid-send -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}" --content-string "hello world" qpid-receive -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
This section describes how to enable SSL/TLS security for the AMQP protocol, where the connection is made between:
- A-MQ broker, deployed on a Linux OS, and
- Qpid C++ client, deployed on a Windows OS.
Configuring SSL/TLS for the broker on Linux 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Follow these steps to enable SSL/TLS security for the AMQP endpoint of a broker running on a Linux platform:
- Create a new certificate,
test.jks
, for testing purposes:keytool -genkey -alias jboss -keyalg RSA -keystore test.jks -storepass password -dname "CN=test,O=test"
keytool -genkey -alias jboss -keyalg RSA -keystore test.jks -storepass password -dname "CN=test,O=test"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Store the new certificate file,test.jks
, in the broker's${A-MQ_HOME}/etc/
directory. - Configure the broker to use the
test.jks
certificate and enable SSL/TLS on the broker's AMQP connector by editing the${A-MQ_HOME}/etc/activemq.xml
file as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteFor more details about the broker configuration, see Securing a Broker using SSL/TLS. - Export the certificate in a format that can be used by the Qpid C++ client running on Windows (in the next step):
keytool -exportcert -rfc -keystore test.jks -storepass password -alias jboss -file ./sample_cert.cer
keytool -exportcert -rfc -keystore test.jks -storepass password -alias jboss -file ./sample_cert.cer
Copy to Clipboard Copied! Toggle word wrap Toggle overflow You need to copy the resultingsample_cert.cer
file to the Windows machine. One way of doing this is to use the secure copy command,scp
, to copy thesample_cert.cer
file securely across the network:scp sample_cert.cer ${USER_NAME}@0.0.0.0:${CLIENT_TARGET_PATH}
scp sample_cert.cer ${USER_NAME}@0.0.0.0:${CLIENT_TARGET_PATH}
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Where${USER_NAME}
is the relevant user name on the Windows machine and${CLIENT_TARGET_PATH}
is the location on the Windows file system where you want to copy the certificate.
Configuring SSL/TLS on the client side 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
Follow these steps to enable SSL/TLS security on a Qpid C++ client deployed on a Windows machine:
- Set up the client environment, using the
MMC.exe
utility to install thesample_cert.cer
certificate into "Trusted Root Certification Authorities", as follows:"Console Root" -> "Trusted Root Certification Authorities" -> "Certificates" Right Click -> "All Tasks" -> "Import"
"Console Root" -> "Trusted Root Certification Authorities" -> "Certificates" Right Click -> "All Tasks" -> "Import"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Test the new configuration using the
qpid-send
command and theqpid-receive
command:qpid-send -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}" --content-string "hello world" qpid-receive -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}"
qpid-send -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}" --content-string "hello world" qpid-receive -b amqp:ssl:0.0.0.0:61617 -a TestQueue --connection-options "{protocol:amqp1.0, ssl_ignore_hostname_verification_failure:true, username:admin, password:admin}"
Copy to Clipboard Copied! Toggle word wrap Toggle overflow