pulsar-client 1.11.0-rc.2 → 1.11.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/package.json +2 -2
- package/src/Client.js +8 -1
- package/src/Reader.cc +13 -11
- package/tests/reader.test.js +41 -0
package/README.md
CHANGED
|
@@ -23,8 +23,9 @@
|
|
|
23
23
|
|
|
24
24
|
The Pulsar Node.js client can be used to create Pulsar producers and consumers in Node.js. For the supported Pulsar features, see [Client Feature Matrix](https://pulsar.apache.org/client-feature-matrix/).
|
|
25
25
|
|
|
26
|
-
This library works only in Node.js
|
|
27
|
-
[node-addon-api](https://github.com/nodejs/node-addon-api) module to wrap the C++ library.
|
|
26
|
+
This library works only in Node.js 12.3 or later because it uses:
|
|
27
|
+
1. The [node-addon-api](https://github.com/nodejs/node-addon-api) module to wrap the C++ library.
|
|
28
|
+
2. The [Mozilla CA](https://nodejs.org/api/tls.html#tlsrootcertificates) file, which is provided by Node.js v12.3.0 and subsequent versions.
|
|
28
29
|
|
|
29
30
|
## Getting Started
|
|
30
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pulsar-client",
|
|
3
|
-
"version": "1.11.0-rc.
|
|
3
|
+
"version": "1.11.0-rc.4",
|
|
4
4
|
"description": "Pulsar Node.js client",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"gypfile": true,
|
|
34
34
|
"engines": {
|
|
35
|
-
"node": ">=
|
|
35
|
+
"node": ">=12.3.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@seadub/clang-format-lint": "0.0.2",
|
package/src/Client.js
CHANGED
|
@@ -57,7 +57,14 @@ class Client {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
static genCertFile() {
|
|
60
|
-
|
|
60
|
+
try {
|
|
61
|
+
if (fs.existsSync(certsFilePath)) {
|
|
62
|
+
fs.unlinkSync(certsFilePath);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error(err);
|
|
66
|
+
}
|
|
67
|
+
|
|
61
68
|
const fd = fs.openSync(certsFilePath, 'a');
|
|
62
69
|
try {
|
|
63
70
|
tls.rootCertificates.forEach((cert) => {
|
package/src/Reader.cc
CHANGED
|
@@ -60,17 +60,19 @@ struct ReaderListenerProxyData {
|
|
|
60
60
|
void ReaderListenerProxy(Napi::Env env, Napi::Function jsCallback, ReaderListenerProxyData *data) {
|
|
61
61
|
Napi::Object msg = Message::NewInstance({}, data->cMessage);
|
|
62
62
|
Reader *reader = data->reader;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
// `reader` might be null in certain cases, segmentation fault might happend without this null check.
|
|
64
|
+
if (reader) {
|
|
65
|
+
Napi::Value ret = jsCallback.Call({msg, reader->Value()});
|
|
66
|
+
if (ret.IsPromise()) {
|
|
67
|
+
Napi::Promise promise = ret.As<Napi::Promise>();
|
|
68
|
+
Napi::Value thenValue = promise.Get("then");
|
|
69
|
+
if (thenValue.IsFunction()) {
|
|
70
|
+
Napi::Function then = thenValue.As<Napi::Function>();
|
|
71
|
+
Napi::Function callback =
|
|
72
|
+
Napi::Function::New(env, [data](const Napi::CallbackInfo &info) { data->callback(); });
|
|
73
|
+
then.Call(promise, {callback});
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
data->callback();
|
package/tests/reader.test.js
CHANGED
|
@@ -130,5 +130,46 @@ const baseUrl = 'http://localhost:8080';
|
|
|
130
130
|
await reader.close();
|
|
131
131
|
await client.close();
|
|
132
132
|
});
|
|
133
|
+
|
|
134
|
+
test('Reader should not throw segmentation fault when create and close', async () => {
|
|
135
|
+
const NUM_ITS = 1000;
|
|
136
|
+
const its = Array.from({ length: NUM_ITS }, (_, i) => i);
|
|
137
|
+
|
|
138
|
+
const client = new Pulsar.Client({
|
|
139
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const producer = await client.createProducer({
|
|
143
|
+
topic: 'persistent://public/default/my-topic',
|
|
144
|
+
sendTimeoutMs: 30000,
|
|
145
|
+
batchingEnabled: true,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// Send messages
|
|
149
|
+
for (let i = 0; i < 10; i += 1) {
|
|
150
|
+
const msg = `my-message-${i}`;
|
|
151
|
+
producer.send({
|
|
152
|
+
data: Buffer.from(msg),
|
|
153
|
+
});
|
|
154
|
+
console.log(`Sent message: ${msg}`);
|
|
155
|
+
}
|
|
156
|
+
await producer.flush();
|
|
157
|
+
|
|
158
|
+
await Promise.all(
|
|
159
|
+
its.map(async () => {
|
|
160
|
+
const reader = await client.createReader({
|
|
161
|
+
topic: 'persistent://public/default/my-topic',
|
|
162
|
+
startMessageId: Pulsar.MessageId.earliest(),
|
|
163
|
+
listener: (message) => {
|
|
164
|
+
console.log(message.getData().toString());
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
await reader.close();
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
await producer.close();
|
|
171
|
+
await client.close();
|
|
172
|
+
expect(true).toBe(true);
|
|
173
|
+
});
|
|
133
174
|
});
|
|
134
175
|
})();
|