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.Ce contenu n'est pas disponible dans la langue sélectionnée.
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 Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Introduction to C++ AMQP 1.0 Client API Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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 Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
You can Download A-MQ C++ client from the Red Hat Customer Portal C++ Client
3.5.2. C++ Example Clients Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
A Simple Messaging Program in C++ Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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
SimpleAsyncConsumerclass. 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
runConsumermethod 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 theSimpleAsyncConsumerinherits fromcms::MessageListenerso that it can register itself as a Message Listener with theMessageConsumercreated inrunConsumermethod. - 3
- All the messages received by the application are dispatched to the
onMessagemethod and if the message is a TextMessage its contents are printed on the screen.
Example 3.14. A simple Asynchronous producer
- 1
- The
SimpleProducerclass 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
runmethod publishes the specified number of messages. Once the run method completes, the client can close theSimpleProducerapplication by calling theclose()method, which cleans up the allocated CMS resource and exits the application.
3.5.3. C++ Client on RHEL for SSL based communication with A-MQ Broker Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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 Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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.jkscertificate and enable SSL/TLS on the broker's AMQP connector by editing the${A-MQ_HOME}/etc/activemq.xmlfile 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.cerCopy to Clipboard Copied! Toggle word wrap Toggle overflow You need to copy the resultingsample_cert.cerfile to the client RHEL machine. One way of doing this is to use the secure copy command,scp, to copy thesample_cert.cerfile 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 Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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-sendandqpid-receivepackages 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-develCopy to Clipboard Copied! Toggle word wrap Toggle overflow - The
keytoolcommand 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_64Copy 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.cercertificate: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.cerCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Set the following environment variables:
export QPID_SSL_CERT_DB=${YOUR_WORK_PATH}/nssdbexport QPID_SSL_CERT_DB=${YOUR_WORK_PATH}/nssdbCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Test the new configuration using the
qpid-sendcommand and theqpid-receivecommand: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
3.5.4. C++ Client on Windows for SSL-Based Communication with A-MQ Broker Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
Overview Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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 Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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.jkscertificate and enable SSL/TLS on the broker's AMQP connector by editing the${A-MQ_HOME}/etc/activemq.xmlfile 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.cerCopy to Clipboard Copied! Toggle word wrap Toggle overflow You need to copy the resultingsample_cert.cerfile to the Windows machine. One way of doing this is to use the secure copy command,scp, to copy thesample_cert.cerfile 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 Copier lienLien copié sur presse-papiers!
Copier lienLien copié sur presse-papiers!
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.exeutility to install thesample_cert.cercertificate 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-sendcommand and theqpid-receivecommand: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