Chapter 4. Examples
This chapter demonstrates the use of AMQ C++ through example programs.
For more examples, see the AMQ C++ example suite and the Qpid Proton C++ examples.
The code presented in this guide uses C++11 features. AMQ C++ is also compatible with C++03, but the code requires minor modifications.
4.1. Sending messages Copy linkLink copied to clipboard!
This client program connects to a server using <connection-url>
, creates a sender for target <address>
, sends a message containing <message-body>
, closes the connection, and exits.
Example: Sending messages
Running the example
To run the example program, copy it to a local file, compile it, and execute it from the command line. For more information, see Chapter 3, Getting started.
g++ send.cpp -o send -std=c++11 -lstdc++ -lqpid-proton-cpp ./send amqp://localhost queue1 hello
$ g++ send.cpp -o send -std=c++11 -lstdc++ -lqpid-proton-cpp
$ ./send amqp://localhost queue1 hello
4.2. Receiving messages Copy linkLink copied to clipboard!
This client program connects to a server using <connection-url>
, creates a receiver for source <address>
, and receives messages until it is terminated or it reaches <count>
messages.
Example: Receiving messages
Running the example
To run the example program, copy it to a local file, compile it, and execute it from the command line. For more information, see Chapter 3, Getting started.
g++ receive.cpp -o receive -std=c++11 -lstdc++ -lqpid-proton-cpp ./receive amqp://localhost queue1
$ g++ receive.cpp -o receive -std=c++11 -lstdc++ -lqpid-proton-cpp
$ ./receive amqp://localhost queue1