All Products
Search
Document Center

ApsaraMQ for RocketMQ:Environment preparation

Last Updated:Sep 22, 2025

The underlying layer of Apache RocketMQ 5.0 SDK for C++ is based on gRPC. This topic describes how to compile Apache RocketMQ SDK for C++ using source code.

Before you start

  • Install GCC

    To ensure that Apache RocketMQ SDK 5.0 SDK for C++ has the same compatibility matrix as that of gRPC, the compilation environment must meet the following requirements:

    • C++ 11 or later is used for the compilation. The corresponding GCC version is 4.8.5 or later. We recommend that you use GCC 10.2 or later.

    • You can define a macro to support C++ 17. The corresponding GCC version is 7. You can run the -std=c++17 or -std=gnu++17 command to enable C++ 17.

  • Install CMake

    CMake 3.13 or later is required.

  • Install OpenSSL

    OpenSSL 1.1.1 is required.

  • Install protobuf

    You can select a version based on your business requirements.

Procedure

  1. Install gflags and the gRPC dependency.

    • Compile and install gflags.

      wget -O gflags-2.2.2.tar.gz https://github.com/gflags/gflags/archive/v2.2.2.tar.gz
      tar -xvzf gflags-2.2.2.tar.gz
      cd gflags-2.2.2/
      mkdir build && cd build
      cmake -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON ..
      make
      make install
      cd
      
      # When you use gflags, make sure to load the library.
      cat >> ~/.bashrc << EOF
      export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib
      EOF
      source ~/.bashrc
    • Compile and install gRPC. We recommend that you use gRPC 1.46.3. Later gRPC versions may not be compatible with Apache RocketMQ 5.0 SDK for C++.

      export MY_INSTALL_DIR=$HOME/grpc
      
      mkdir -p $MY_INSTALL_DIR
      
      # Add the local bin folder to your path variable, for example:
      export PATH="$MY_INSTALL_DIR/bin:$PATH"
      
      git clone --recurse-submodules \
          -b v1.46.3 --depth 1 --shallow-submodules \
          https://github.com/grpc/grpc
      
      cd grpc
      mkdir -p cmake/build
      pushd cmake/build
      cmake -DgRPC_INSTALL=ON \
          -DgRPC_BUILD_TESTS=OFF \
          -DCMAKE_INSTALL_PREFIX=$MY_INSTALL_DIR \
            ../..
      
      make -j 32
      make install
      popd
  2. Build the source code. Apache RocketMQ SDK for C++ allows you to build source code using CMake and Bazel. We recommend that you use CMake. In this topic, Apache RocketMQ 5.0.2 SDK for C++ is used.

    CMake (recommended)

    wget -O rocketmq-clients-cpp-5.0.3.tar.gz https://github.com/apache/rocketmq-clients/archive/refs/tags/cpp-5.0.3.tar.gz
    tar -xvzf rocketmq-clients-cpp-5.0.3.tar.gz
    cd rocketmq-clients-cpp-5.0.3/cpp
    mkdir build && cd build
    cmake ..
    make

    Bazel

    wget -O rocketmq-clients-cpp-5.0.3.tar.gz https://github.com/apache/rocketmq-clients/archive/refs/tags/cpp-5.0.3.tar.gz
    tar -xvzf rocketmq-clients-cpp-5.0.3.tar.gz
    cd rocketmq-clients-cpp-5.0.3/cpp
    bazel build //...
  3. Obtain the resource information.

    You must create the resources, including the instance, topic, and consumer group, that are involved in the SDK code in the ApsaraMQ for RocketMQ console in advance. For more information, see Step 2: Create resources.

  4. Modify the parameters in the sample code based on the resource information obtained in Step 3. Then, compile and run the sample code.