This topic describes the preparations, instructions, and precautions for accessing Message Queue for Apache RocketMQ by using the SDK for C++ V2.X.X and later so that you can use the SDK for C++ to send and receive messages.

Before you start, take note of the following points:

  • This topic describes only the SDK for C++ V2.X.X and later. For information about how to upgrade from V1.X.X to V2.X.X and later, see Environment preparation (V1.X.X).
  • You must create the topics and group IDs that are referred to in the code in the console. Message tags can be specified by application users. For more information about how to create a message tag, see Create resources.
  • An application that uses Message Queue for Apache RocketMQ must be deployed on an Alibaba Cloud Elastic Compute Service (ECS) instance.

The SDK for C++ V2.X.X and later supports only the Linux CentOS 6/RHEL 6 and CentOS 7/RHEL 7 series. For more information about how to download the SDK for C++, see Release notes.

After you download the SDK for C++, select the version that corresponds to your operating system kernel for decompression. The following directory structure is generated:

  • demos/

    Contains examples on how to send and consume normal messages and ordered messages and how to send messages in one-way transmission mode. This directory also contains the CMakeList.txt file that is used to compile and manage demos.

  • include/

    Contains the header files you need for your own program.

  • lib/

    Contains dynamic libraries based on x86_64. The libraries include the interface library and the core library.

  • changelog

    Contains bug fixes and new features in the new releases.

Linux C++ SDK dynamic library solution

Starting June 28, 2019, the new SDK version provides only dynamic library solutions. The Message Queue for Apache RocketMQ library file is in the lib/ directory. You need to link the and when the business side generates the executable file. Because the demos introduces the features of C++ 11 and uses CMake to manage it, you need to install CMake 3.0 or above and g++ 4.8 or above in advance.

Important Due to the introduction of Dual ABI in GCC 5.x and above, please add the -D_GLIBCXX_USE_CXX11_ABI=0 compilation option when compiling links.

The following sample code provides an example on how to use demos:

# The path where the downloaded SDK is decompressed. 
cd aliyun-mq-linux-cpp-sdk 
# Go to the demos directory, modify the demos file, and enter the topics and keys that you created in the Message Queue for Apache RocketMQ console. 
cd demos 
# Detect dependencies and generate compilation scripts.
cmake .  
# Perform the compilation operation. 
# Run the program in the generated executable directory.
cd bin