All Products
Search
Document Center

ApsaraMQ for RocketMQ:Sample code for C++

Last Updated:Mar 11, 2026

Send and receive messages with the Apache RocketMQ 5.x SDK for C++. The following table lists the sample code for each message type and consumer pattern.

Sample code by message type

Message typeProducerPushConsumerSimpleConsumer
Normal messagesSync: ExampleProducer.cppExamplePushConsumer.cppExampleSimpleConsumer.cpp
Async: ExampleProducerWithAsync.cpp
Ordered messagesExampleProducerWithFifoMessage.cpp
Scheduled and delayed messagesExampleProducerWithTimedMessage.cpp
Transactional messagesExampleProducerWithTransactionalMessage.cpp

Parameters

Replace the following parameters in the sample code with your actual values before you run the code.

ParameterExampleDescription
access_pointrmq-cn-xxx.{regionId}.rmq.aliyuncs.com:8080The endpoint of your ApsaraMQ for RocketMQ instance. Specify the public endpoint for Internet access or the VPC endpoint for VPC access. For more information, see Obtain the endpoint of an instance.
topicnormal_testThe topic to which messages are sent or from which messages are consumed. Create the topic in advance. For more information, see Create a topic.
groupGID_testThe consumer group for message consumption. Create the consumer group in advance. For more information, see Create a consumer group.
access_key1XVg0hzgKm******The username of your ApsaraMQ for RocketMQ instance. Required for Internet access. For VPC access, required only if the instance is serverless and the authentication-free in VPCs feature is disabled. For more information, see Obtain the username and password of an instance.
access_secretijSt8rEc45******The password of your ApsaraMQ for RocketMQ instance. Required for Internet access. For VPC access, required only if the instance is serverless and the authentication-free in VPCs feature is disabled. For more information, see Obtain the username and password of an instance.