DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Anthropic’s Model Context Protocol (MCP): A Developer’s Guide to Long-Context LLM Integration
  • The Agent Protocol Stack: MCP vs. A2A vs. AG-UI
  • AWS Kiro: The Agentic IDE That Makes Specs the Unit of Work
  • Understanding the Shifting Protocols That Secure AI Agents

Trending

  • Java Backend Development in the Era of Kubernetes and Docker
  • Lease Coordination Under Serializable Isolation in CockroachDB
  • The Prompt Isn't Hiding Inside the Image
  • Stop Guessing, Start Seeing: A Five -Layer Framework for Monitoring Distributed Systems
  1. DZone
  2. Software Design and Architecture
  3. Integration
  4. Develop and Debug C++ Messaging Client Using AMQP Protocol in Apache ActiveMQ Artemis

Develop and Debug C++ Messaging Client Using AMQP Protocol in Apache ActiveMQ Artemis

In this tutorial, see how to develop and debug a C++ messaging client using AMQP protocol in Apache ActiveMQ Artemis.

By 
Chandra Shekhar Pandey user avatar
Chandra Shekhar Pandey
·
Apr. 14, 20 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
15.5K Views

Join the DZone community and get the full member experience.

Join For Free

Apache ActiveMQ Artemis is one of the most popular open source messaging brokers. It supports multiple messaging protocols like AMQP, STOMP, Openwire, MQTT, and native core. In this article, we will discuss C++ clients, including producer and consumer. These clients are based on the Qpid Proton library, which is based on AMQP protocol.

These examples are already available in the Qpid Proton website. We will demonstrate how we can execute and debug these examples using opensource IDE CodeBlock IDE. This CodeBlock IDE can be very useful for basic or intermediate C++ projects. I have been working in Linux OS with Java language and Eclipse IDE. Being a beginner with C++, I wanted a similar IDE in Linux (Fedora) for C++. Specifically, I was looking for Debug Tools to analyze these examples. It is not as feature-rich as the Eclipse IDE, but with CodeBlock IDE, I was able to debug these clients.

You can find these examples in my personnel GitHub link. There are three separate CodeBlock projects:

  1. AMQCPPTest: It is a simple HelloWorld program in C++, which just sends a message to the broker and consume also. This example might not be very useful because mostly the sender/producer and receiver/consumer are different client/projects. But it is the best example to start with and understand the concepts.
  2. AsyncReceive: It is the receiver program. It receives or consumes messages sent by AsyncSend Project.
  3. AsyncSend: It is a project that sends messages to the broker.  It is based on a proton example simple_send.cpp.

Prerequisites

Follow this documentation to install the proton c++ client. I had Fedora 31, and I used the following command to install the Proton C++ client library.

Shell
 




xxxxxxxxxx
1


 
1
sudo yum install qpid-proton-cpp-devel qpid-proton-cpp-docs



Let's get rolling now:

Step 1. Download Apache ActiveMQ Artemis Broker from this link.

Step 2. Unzip this and create a broker instance broker1_cpp with the following command. I have created a folder artemis_instance, I will create a broker instance within this folder with the following command:

Shell
 




xxxxxxxxxx
1
30


 
1
[chandrashekhar@localhost artemis_instance]$ ../apache-artemis-2.11.0/bin/artemis create broker1_cpp
2
 
          
3
Creating ActiveMQ Artemis instance at: /home/chandrashekhar/Development/AMQ_RH/artemis_instance/broker1_cpp
4
 
          
5
--user: is a mandatory property!
6
 
          
7
Please provide the default username:
8
 
          
9
admin
10
 
          
11
--password: is mandatory with this configuration:
12
 
          
13
Please provide the default password:
14
 
          
15
--allow-anonymous | --require-login: is a mandatory property!
16
 
          
17
Allow anonymous access?, valid values are Y,N,True,False
18
 
          
19
Y
20
 
          
21
Auto tuning journal ...
22
 
          
23
done! Your system can make 5.68 writes per millisecond, your journal-buffer-timeout will be 176000
24
 
          
25
You can now start the broker by executing:  
26
   "/home/chandrashekhar/Development/AMQ_RH/artemis_instance/broker1_cpp/bin/artemis" run
27
 
          
28
Or you can run the broker in the background using:
29
 
          
30
"/home/chandrashekhar/Development/AMQ_RH/artemis_instance/broker1_cpp/bin/artemis-service" start



Step 3: Start broker instance broker1_cpp with command:

Shell
 




xxxxxxxxxx
1


 
1
[chandrashekhar@localhost bin]$ pwd
2
/home/chandrashekhar/Development/AMQ_RH/artemis_instance/broker1_cpp/bin
3
[chandrashekhar@localhost bin]$ ./artemis run
4
 
          



Step 4: You can create a queue example with command:

Shell
 




xxxxxxxxxx
1
15


 
1
[chandrashekhar@localhost bin]$ ./artemis queue create --name exampleQueue --auto-create-address --anycast
2
 
          
3
--address: is a mandatory property!
4
Enter the address name. <Enter for exampleQueue>
5
 
          
6
 
          
7
--durable: is a mandatory property!
8
Is this a durable queue, valid values are Y,N,True,False
9
Y
10
 
          
11
--purge-on-no-consumers: is a mandatory property!
12
Purge the contents of the queue once there are no consumers, valid values are Y,N,True,False
13
N
14
Queue [name=exampleQueue, address=exampleQueue, routingType=ANYCAST, durable=true, purgeOnNoConsumers=false, autoCreateAddress=false, exclusive=false, lastValue=false, lastValueKey=null, nonDestructive=false, consumersBeforeDispatch=0, delayBeforeDispatch=-1, autoCreateAddress=false] created successfully.
15
[chandrashekhar@localhost bin]$



Step 5: From CodeBlock IDE, import project AMQCPPTest.

a. Open an existing project


                                                                        b. Select project


c. Run/Execute Program


d. Output


Step 6. Check Queue Statistics

Shell
 




xxxxxxxxxx
1


 
1
[chandrashekhar@localhost bin]$ ./artemis queue stat
2
|NAME                     |ADDRESS                  |CONSUMER_COUNT |MESSAGE_COUNT |MESSAGES_ADDED |DELIVERING_COUNT |MESSAGES_ACKED |SCHEDULED_COUNT |ROUTING_TYPE |
3
 
          
4
|exampleQueue             |exampleQueue             |0              |0             |1              |0                |1              |0               |ANYCAST      |
5
 
          
6
[chandrashekhar@localhost bin]$ 



Step 7. Debug C++ code from CodeBlock IDE. From the menu bar with path DEBUG > Debugging windows, we can select plugin watches and Memory dump. To Debug set breakpoints and execute the Red Play button in the tool bar, you can debug as in screenshot.

                                                                                 e. Debugger


Step 8. Check message details like headers and the body for example queue from Apache ActiveMQ Artemis GUI console using url http://localhost:8161. You can login with username and password admin, which we set while create broker instance in beginning. These messages were sent using AsyncSend project.

                                                                              f. GUI console


Step 9. You might make mistakes building this project. You would have to add the qpid-proton-cpp library so that dependencies can be resolved. Follow the screenshot to add.

                                                                      g. Add library

Step 10. We can always compile and run these C++ class files with the following command.

Shell
 




x


 
1
[chandrashekhar@localhost AsyncSend]$ g++ simpleSend.cpp -lqpid-proton-cpp -o simplSend.out
2
[chandrashekhar@localhost AsyncSend]$ ./simplSend.out 
3
credits before send: 1000
4
credits after send: 900
5
credits before send: 900
6
credits after send: 900
7
all messages confirmed
8
[chandrashekhar@localhost AsyncSend]$ 
9
 
          


 

That's it. I believe you will find this article informative and interesting. 

Apache ActiveMQ Debug (command) Protocol (object-oriented programming) Integrated development environment

Opinions expressed by DZone contributors are their own.

Related

  • Anthropic’s Model Context Protocol (MCP): A Developer’s Guide to Long-Context LLM Integration
  • The Agent Protocol Stack: MCP vs. A2A vs. AG-UI
  • AWS Kiro: The Agentic IDE That Makes Specs the Unit of Work
  • Understanding the Shifting Protocols That Secure AI Agents

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook