commit | cd2a307d99c1a4ae650d31a1f25371bf22bd2d6b | [log] [tgz] |
---|---|---|
author | Yunze Xu <xyzinfernity@163.com> | Fri Feb 10 17:53:34 2023 +0800 |
committer | GitHub <noreply@github.com> | Fri Feb 10 17:53:34 2023 +0800 |
tree | b39595bf11ca45e047ce0844ee338db503c1f367 | |
parent | 15d0223c740aa84c2e9d9fc38ba8ec7f360a487d [diff] |
Make it compatible with GLIBCXX_3.4.19 (CentOS 7) (#288) * Make it compatible with GLIBCXX_3.4.19 (CentOS 7) Fixes https://github.com/apache/pulsar-client-node/issues/286 ### Motivation The maximum GLIBCXX version on CentOS 7 is 3.4.19. If we want to use the Pulsar Node client on CentOS 7, we have to upgrade the libstdc++.so. The reason is the libstdc++ version is too high for some systems. https://github.com/apache/pulsar-client-node/pull/285 downgrades the base image to `node:18-buster` but it still requires the `GLIBCXX_3.4.22`. ### Modifications - Use `centos:7` as the base image to build `Pulsar.node` for glibc-based Linux distributions. - Add `load_test.sh` to verify `Pulsar.node` can be loaded by other docker images and test Node.js 16 and 19 on Debian buster and bullseye. * Avoid modifying the Node.js scripts * Remove the TAR each time the script is executed * Fix the binary name changed in https://github.com/apache/pulsar-client-node/pull/290
The Pulsar Node.js client can be used to create Pulsar producers and consumers in Node.js.
This library works only in Node.js 10.x or later because it uses the node-addon-api module to wrap the C++ library.
Note
These instructions are only available for versions after 1.8.0. For versions previous to 1.8.0, you need to install the C++ client first. Please switch to the corresponding version branch of this repo to read the specific instructions.
To run the examples, skip this section.
To use the Pulsar Node.js client in your project, run:
npm install pulsar-client
or
yarn add pulsar-client
Then you can run the following simple end-to-end example:
const Pulsar = require('pulsar-client'); (async () => { // Create a client const client = new Pulsar.Client({ serviceUrl: 'pulsar://localhost:6650' }); // Create a producer const producer = await client.createProducer({ topic: 'persistent://public/default/my-topic', }); // Create a consumer const consumer = await client.subscribe({ topic: 'persistent://public/default/my-topic', subscription: 'sub1' }); // Send a message producer.send({ data: Buffer.from("hello") }); // Receive the message const msg = await consumer.receive(); console.log(msg.getData().toString()); consumer.acknowledge(msg); await producer.close(); await consumer.close(); await client.close(); })();
You should find the output as:
hello
You can see more examples in the examples directory. However, since these examples might use an API that was not released yet, you need to build this module. See the next section.
Note
Build from source code requires the Node.js version greater than 16.18
First, clone the repository.
git clone https://github.com/apache/pulsar-client-node.git cd pulsar-client-node
Since this client is a C++ addon that depends on the Pulsar C++ client, you need to install the C++ client first. You need to ensure there is a C++ compiler that supports C++11 installed in your system.
pkg/linux/download-cpp-client.sh
pkg\windows\download-cpp-client.bat
pkg/mac/build-cpp-deps-lib.sh pkg/mac/build-cpp-lib.sh
After the C++ client is installed, run the following command to build this C++ addon.
npm install
To verify it has been installed successfully, you can run an example like:
node examples/producer
You should find the output as:
Sent message: my-message-0 Sent message: my-message-1 Sent message: my-message-2 Sent message: my-message-3 Sent message: my-message-4 Sent message: my-message-5 Sent message: my-message-6 Sent message: my-message-7 Sent message: my-message-8 Sent message: my-message-9