Examples for using the API to publish and consume messages can be found on https://github.com/apache/pulsar/tree/master/pulsar-client-cpp/examples
- A C++ compiler that supports C++11, like GCC >= 4.8
- CMake >= 3.4
- Boost
- Protocol Buffer >= 3
- libcurl
- openssl
It's recommended to use Protocol Buffer 2.6 because it's verified by CI, but 3.x also works.
The default supported compression types are:
CompressionNoneCompressionLZ4
If you want to enable other compression types, you need to install:
If you want to build and run the tests, you need to install GTest. Otherwise, you need to add CMake option -DBUILD_TESTS=OFF.
If you don't want to build Python client since boost-python may not be easy to install, you need to add CMake option -DBUILD_PYTHON_WRAPPER=OFF.
If you want to use ClientConfiguration::setLogConfFilePath, you need to install the Log4CXX and add CMake option -DUSE_LOG4CXX=ON.
Pulsar C++ Client Library has been tested on:
- Linux
- Mac OS X
- Windows x64
sudo apt-get install -y g++ cmake libssl-dev libcurl4-openssl-dev \ libprotobuf-dev libboost-all-dev libgtest-dev libgmock-dev \ protobuf-compilercd pulsar-client-cpp cmake . makelib/libpulsar.so lib/libpulsar.a perf/perfProducer perf/perfConsumer brew install openssl protobuf boost boost-python3 googletest zstd snappycd pulsar-client-cpp/ cmake . makelib/libpulsar.dylib lib/libpulsar.a perf/perfProducer perf/perfConsumer Install with vcpkg
It's highly recommended to use vcpkg for C++ package management on Windows. It's easy to install and well supported by Visual Studio (2015/2017/2019) and CMake. See here for quick start.
Take Windows 64-bit library as an example, you only need to run
vcpkg install --feature-flags=manifests --triplet x64-windowsNOTE: For Windows 32-bit library, change
x64-windowstox86-windows, see here for more details about the triplet concept in Vcpkg.
The all dependencies, which are specified by vcpkg.json, will be installed in vcpkg_installed/ subdirectory,
With vcpkg, you only need to run two commands:
cmake \ -B ./build \ -A x64 \ -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF \ -DVCPKG_TRIPLET=x64-windows \ -DCMAKE_BUILD_TYPE=Release \ -S . cmake --build ./build --config ReleaseThen all artifacts will be built into build subdirectory.
NOTE
- For Windows 32-bit, you need to use
-A Win32and-DVCPKG_TRIPLET=x86-windows.- For MSVC Debug mode, you need to replace
ReleasewithDebugfor bothCMAKE_BUILD_TYPEvariable and--configoption.
You need to install dlfcn-win32 in addition.
If you installed the dependencies manually, you need to run
#If all dependencies are in your path, all that is necessary is pulsar-client-cpp/cmake . #if all dependencies are not in your path, then passing in a PROTOC_PATH and CMAKE_PREFIX_PATH is necessary pulsar-client-cpp/cmake -DPROTOC_PATH=C:/protobuf/bin/protoc -DCMAKE_PREFIX_PATH="C:/boost;C:/openssl;C:/zlib;C:/curl;C:/protobuf;C:/googletest;C:/dlfcn-win32" . #This will generate pulsar-cpp.sln. Open this in Visual Studio and build the desired configurations.pulsar-client-cpp/build/lib/Release/pulsar.lib pulsar-client-cpp/build/lib/Release/pulsar.dll pulsar-client-cpp/build/lib/Release pulsar-client-cpp/vcpkg_installed pulsar-client-cpp/build/examples/Release # Execution # Start standalone broker ./pulsar-test-service-start.sh # Run the tests cd tests ./pulsar-tests # When no longer needed, stop standalone broker ./pulsar-test-service-stop.shIt's required to install LLVM for clang-tidy and clang-format. Pulsar C++ client use clang-format 6.0+ to format files. make format automatically formats the files.
We welcome contributions from the open source community, kindly make sure your changes are backward compatible with GCC 4.8 and Boost 1.53.