All Products
Search
Document Center

ApsaraMQ for RocketMQ:Sample code

Last Updated:Mar 26, 2025

This topic describes the sample code for sending and receiving messages by using Apache RocketMQ 5.x SDK for C++.

Message type

Sample code for sending messages

Sample code for receiving messages

PushConsumer

SimpleConsumer

Normal messages

ExamplePushConsumer.cpp

ExampleSimpleConsumer.cpp

Ordered messages

ExampleProducerWithFifoMessage.cpp

Scheduled and delayed messages

ExampleProducerWithTimedMessage.cpp

Transactional messages

ExampleProducerWithTransactionalMessage.cpp

Parameters

Parameter

Example

Description

access_point

rmq-cn-xxx.{regionId}.rmq.aliyuncs.com:8080

The endpoint of the ApsaraMQ for RocketMQ instance. For information about how to obtain the endpoint, see Obtain the endpoint of an instance.

  • If you access the instance over the Internet, specify the public endpoint.

  • If you access the instance in a VPC, specify the VPC endpoint.

topic

normal_test

The topic to which messages are sent or from which messages are consumed in the ApsaraMQ for RocketMQ instance.

You must create the topic on the ApsaraMQ for RocketMQ instance in advance. For more information, see Create a topic.

group

GID_test

The consumer group that is used by consumers to consume messages in the ApsaraMQ for RocketMQ instance.

You must create the consumer group on the ApsaraMQ for RocketMQ instance in advance. For more information, see Create a consumer group.

access_key

1XVg0hzgKm******

The username of the ApsaraMQ for RocketMQ instance. If you access the instance over the Internet, you must specify the username. If you access the instance in a VPC, you need to specify the username only if the instance is a serverless instance and the authentication-free in VPCs feature is disabled for the instance.

For information about how to obtain the username, see Obtain the username and password of an instance.

access_secret

ijSt8rEc45******

The password of the ApsaraMQ for RocketMQ instance. If you access the instance over the Internet, you must specify the password. If you access the instance in a VPC, you need to specify the password only if the instance is a serverless instance and the authentication-free in VPCs feature is disabled for the instance.

For information about how to obtain the password, see Obtain the username and password of an instance.