Apache Pulsar NodeJS Client

Clone this repo:
  1. 729ad2a 1.8.0-rc.0 (#232) by Yuto Furuta · 4 days ago master
  2. 73d2715 format ProducerConfig.cc (#233) by Yuto Furuta · 5 days ago
  3. ca54275 Respect maxPendingMessagesAcrossPartitions (#231) by Robert Kawecki · 3 weeks ago
  4. db9ad97 Update C++ client version and compatiblity table to v2.10.1 (#229) by Yuri Mizushima · 5 weeks ago
  5. 1f4c261 Remove node-pre-gyp dependency and config (#228) by Yuri Mizushima · 7 weeks ago

Pulsar Node.js client library

The Pulsar Node.js client can be used to create Pulsar producers and consumers in Node.js.

Requirements

Pulsar Node.js client library is based on the C++ client library. Follow the instructions for C++ library for installing the binaries through RPM, Deb or Homebrew packages.

(Note: you will need to install not only the pulsar-client library but also the pulsar-client-dev library)

Also, this library works only in Node.js 10.x or later because it uses the node-addon-api module to wrap the C++ library.

Compatibility

Compatibility between each version of the Node.js client and the C++ client is as follows:

Node.js clientC++ client
1.0.x2.3.0 or later
1.1.x2.4.0 or later
1.2.x2.5.0 or later
1.3.x2.7.0 or later
1.4.x - 1.6.x2.8.0 or later
1.7.x2.10.1 or later

If an incompatible version of the C++ client is installed, you may fail to build or run this library.

How to install

Install on windows

  1. Build the Pulsar C++ client on windows.
cmake \
 -A x64 \
 -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF \
 -DVCPKG_TRIPLET=x64-windows \
 -DCMAKE_BUILD_TYPE=Release \
 -S .
cmake --config Release
  1. Set the variable PULSAR_CPP_DIR with the pulsar-client-cpp path in a Windows command tool.
# for example
set PULSAR_CPP_DIR=C:\pulsar\pulsar-client-cpp
  1. Set the variable OS_ARCH in a Windows command tool, OS_ARCH is related to the configuration of VCPKG_TRIPLET on the command line above.(Optional)
set OS_ARCH=x64-windows

Install on mac

  1. Install the Pulsar C++ client on mac.
brew install libpulsar
  1. Get the installation path of libpulsar
brew info libpulsar
  1. Set the variable PULSAR_CPP_DIR with the pulsar-client-cpp path in a mac command tool.
# for example
## Intel x86_64
export PULSAR_CPP_DIR=/usr/local/Cellar/libpulsar/2.9.1_1

## Apple Silicon and Homebrew since 3.0.0
## cf. https://brew.sh/2021/02/05/homebrew-3.0.0/
export PULSAR_CPP_DIR=/opt/homebrew/Cellar/libpulsar/2.9.1_1

Install on Linux

  1. Require g++ and make commands to install pulsar-client
# rpm
$ yum install gcc-c++ make

# debian
$ apt-get install g++ make
  1. Download rpm or debian packages.
# Set the version of Pulsar C++ client to install
$ PULSAR_CPP_CLIENT_VERSION=2.9.1

# rpm
$ wget https://archive.apache.org/dist/pulsar/pulsar-${PULSAR_CPP_CLIENT_VERSION}/RPMS/apache-pulsar-client-${PULSAR_CPP_CLIENT_VERSION}-1.x86_64.rpm
$ wget https://archive.apache.org/dist/pulsar/pulsar-${PULSAR_CPP_CLIENT_VERSION}/RPMS/apache-pulsar-client-devel-${PULSAR_CPP_CLIENT_VERSION}-1.x86_64.rpm

# debian
$ wget https://archive.apache.org/dist/pulsar/pulsar-${PULSAR_CPP_CLIENT_VERSION}/DEB/apache-pulsar-client.deb
$ wget https://archive.apache.org/dist/pulsar/pulsar-${PULSAR_CPP_CLIENT_VERSION}/DEB/apache-pulsar-client-dev.deb
  1. Install the Pulsar C++ client.
# rpm
$ rpm -ivh apache-pulsar-client*.rpm

# debian
$ apt install ./apache-pulsar-client*.deb

Install pulsar-client to your project

$ npm install pulsar-client

Sample code

Please refer to examples.

How to build

Install dependent npm modules and build Pulsar client library:

$ git clone https://github.com/apache/pulsar-client-node.git
$ cd pulsar-client-node
$ npm install

Note

If you build pulsar-client-node on windows, you need to set the variable PULSAR_CPP_DIR first, then install npm (run the command npm install) in a Windows command-line tool.

Rebuild Pulsar client library:

$ npm run build

Documentation