commit | 364f36d9a42259fae95f3dfd8c1e7774f9773917 | [log] [tgz] |
---|---|---|
author | Yosi Attias <yosy101@gmail.com> | Thu Mar 26 04:25:33 2020 +0200 |
committer | GitHub <noreply@github.com> | Thu Mar 26 11:25:33 2020 +0900 |
tree | c736d9e9d0d49b9e19b2c22bbe01dbfe13923953 | |
parent | 225d85da22485ed493f17edd6b13e4df2d47dbad [diff] |
Create reference for client (#85) Since we don’t have reference for the client, v8 can garbage collect this instance, which can cause the next code: ``` 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', sendTimeoutMs: 30000, batchingEnabled: true, }); let i =0; async function produceMessage() { i = i + 1; const msg = `my-message-${i}`; const ret = await producer.send({ data: Buffer.from(msg), }); console.log(`Sent message: ${msg}`); console.log(ret); setTimeout(produceMessage, 1000); } produceMessage(); })(); ``` To close the connection suddenly and fail the producer.
The Pulsar Node.js client can be used to create Pulsar producers and consumers in Node.js.
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 between each version of the Node.js client and the C++ client is as follows:
Node.js client | C++ client |
---|---|
1.0.0 | 2.3.0 or later |
1.1.0 | 2.4.0 or later |
If an incompatible version of the C++ client is installed, you may fail to build or run this library.
$ npm install pulsar-client
$ npm install @types/pulsar-client --save-dev
Please refer to examples.
$ git clone https://github.com/apache/pulsar-client-node.git $ cd pulsar-client-node $ npm install
$ npm run build