pulsar-client 1.13.2-rc.1 → 1.14.0-rc.1

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.
Files changed (77) hide show
  1. package/.idea/aws.xml +18 -0
  2. package/.idea/codeStyles/Project.xml +7 -0
  3. package/.idea/codeStyles/codeStyleConfig.xml +5 -0
  4. package/.idea/inspectionProfiles/Project_Default.xml +6 -0
  5. package/.idea/misc.xml +7 -0
  6. package/.idea/modules.xml +9 -0
  7. package/.idea/pulsar-client-node.iml +46 -0
  8. package/.idea/pulsar_client_node.iml +8 -0
  9. package/.idea/vcs.xml +6 -0
  10. package/index.d.ts +17 -0
  11. package/package.json +1 -1
  12. package/src/Client.cc +2 -1
  13. package/src/Client.h +1 -0
  14. package/src/ConsumerConfig.cc +66 -0
  15. package/src/cert.pem +3278 -0
  16. package/.clang-format +0 -26
  17. package/.eslintignore +0 -21
  18. package/.eslintrc.json +0 -22
  19. package/.github/PULL_REQUEST_TEMPLATE.md +0 -85
  20. package/.github/workflows/ci-build-release-napi.yml +0 -211
  21. package/.github/workflows/ci-pr-validation.yml +0 -334
  22. package/build-support/download-release-artifacts.py +0 -77
  23. package/build-support/generate-source-archive.sh +0 -28
  24. package/build-support/pulsar-test-container-start.sh +0 -43
  25. package/build-support/pulsar-test-service-start.sh +0 -39
  26. package/build-support/pulsar-test-service-stop.sh +0 -32
  27. package/build-support/sign-files.sh +0 -32
  28. package/build-support/stage-release.sh +0 -44
  29. package/docs/release-process.md +0 -291
  30. package/examples/certificate/private-key.client-rsa.pem +0 -27
  31. package/examples/certificate/public-key.client-rsa.pem +0 -9
  32. package/examples/consumer-schema.js +0 -66
  33. package/examples/consumer.js +0 -46
  34. package/examples/consumer_listener.js +0 -44
  35. package/examples/consumer_tls_auth.js +0 -51
  36. package/examples/consummer_token_auth.js +0 -50
  37. package/examples/consummer_token_auth_supplier.js +0 -56
  38. package/examples/custom_logger.js +0 -60
  39. package/examples/encryption-consumer.js +0 -47
  40. package/examples/encryption-producer.js +0 -50
  41. package/examples/encryption-reader.js +0 -44
  42. package/examples/producer-schema.js +0 -76
  43. package/examples/producer.js +0 -48
  44. package/examples/producer_tls_auth.js +0 -52
  45. package/examples/producer_token_auth.js +0 -48
  46. package/examples/producer_token_auth_supplier.js +0 -53
  47. package/examples/reader.js +0 -43
  48. package/examples/reader_listener.js +0 -37
  49. package/license-checker-config.json +0 -43
  50. package/license-header.txt +0 -16
  51. package/perf/perf_consumer.js +0 -103
  52. package/perf/perf_producer.js +0 -118
  53. package/pkg/linux/Dockerfile_linux_glibc +0 -31
  54. package/pkg/linux/Dockerfile_linux_musl +0 -32
  55. package/pkg/linux/build-napi-inside-docker.sh +0 -31
  56. package/pkg/linux/download-cpp-client.sh +0 -65
  57. package/pkg/load_test.js +0 -34
  58. package/pkg/mac/download-cpp-client.sh +0 -36
  59. package/pkg/windows/download-cpp-client.bat +0 -12
  60. package/tests/certificate/private-key.client-rsa.pem +0 -27
  61. package/tests/certificate/public-key.client-rsa.pem +0 -9
  62. package/tests/certificate/server.crt +0 -20
  63. package/tests/certificate/server.key +0 -28
  64. package/tests/client.test.js +0 -122
  65. package/tests/conf/standalone.conf +0 -308
  66. package/tests/consumer.test.js +0 -434
  67. package/tests/docker-load-test.sh +0 -35
  68. package/tests/end_to_end.test.js +0 -1447
  69. package/tests/http_utils.js +0 -45
  70. package/tests/load-test.sh +0 -43
  71. package/tests/producer.test.js +0 -160
  72. package/tests/reader.test.js +0 -175
  73. package/tests/run-unit-tests.sh +0 -35
  74. package/tsconfig.json +0 -22
  75. package/tslint.json +0 -9
  76. package/tstest.ts +0 -408
  77. package/typedoc.json +0 -15
@@ -1,434 +0,0 @@
1
- /**
2
- * Licensed to the Apache Software Foundation (ASF) under one
3
- * or more contributor license agreements. See the NOTICE file
4
- * distributed with this work for additional information
5
- * regarding copyright ownership. The ASF licenses this file
6
- * to you under the Apache License, Version 2.0 (the
7
- * "License"); you may not use this file except in compliance
8
- * with the License. You may obtain a copy of the License at
9
- *
10
- * http://www.apache.org/licenses/LICENSE-2.0
11
- *
12
- * Unless required by applicable law or agreed to in writing,
13
- * software distributed under the License is distributed on an
14
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
- * KIND, either express or implied. See the License for the
16
- * specific language governing permissions and limitations
17
- * under the License.
18
- */
19
-
20
- const Pulsar = require('../index');
21
-
22
- (() => {
23
- describe('Consumer', () => {
24
- let client;
25
-
26
- beforeAll(() => {
27
- client = new Pulsar.Client({
28
- serviceUrl: 'pulsar://localhost:6650',
29
- operationTimeoutSeconds: 30,
30
- });
31
- });
32
-
33
- afterAll(async () => {
34
- await client.close();
35
- });
36
-
37
- describe('Create', () => {
38
- test('No Topic', async () => {
39
- await expect(client.subscribe({
40
- subscription: 'sub1',
41
- ackTimeoutMs: 10000,
42
- nAckRedeliverTimeoutMs: 60000,
43
- })).rejects.toThrow('Topic, topics or topicsPattern is required and must be specified as a string when creating consumer');
44
- });
45
-
46
- test('Not String Topic', async () => {
47
- await expect(client.subscribe({
48
- topic: 0,
49
- subscription: 'sub1',
50
- ackTimeoutMs: 10000,
51
- nAckRedeliverTimeoutMs: 60000,
52
- })).rejects.toThrow('Topic, topics or topicsPattern is required and must be specified as a string when creating consumer');
53
- });
54
-
55
- test('Not String TopicsPattern', async () => {
56
- await expect(client.subscribe({
57
- topicsPattern: 0,
58
- subscription: 'sub1',
59
- ackTimeoutMs: 10000,
60
- nAckRedeliverTimeoutMs: 60000,
61
- })).rejects.toThrow('Topic, topics or topicsPattern is required and must be specified as a string when creating consumer');
62
- });
63
-
64
- test('Not Array Topics', async () => {
65
- await expect(client.subscribe({
66
- topics: 0,
67
- subscription: 'sub1',
68
- ackTimeoutMs: 10000,
69
- nAckRedeliverTimeoutMs: 60000,
70
- })).rejects.toThrow('Topic, topics or topicsPattern is required and must be specified as a string when creating consumer');
71
- });
72
-
73
- test('Not String in Array Topics', async () => {
74
- await expect(client.subscribe({
75
- topics: [0, true],
76
- subscription: 'sub1',
77
- ackTimeoutMs: 10000,
78
- nAckRedeliverTimeoutMs: 60000,
79
- })).rejects.toThrow('Topic, topics or topicsPattern is required and must be specified as a string when creating consumer');
80
- });
81
-
82
- test('No Subscription', async () => {
83
- await expect(client.subscribe({
84
- topic: 'persistent://public/default/t1',
85
- ackTimeoutMs: 10000,
86
- nAckRedeliverTimeoutMs: 60000,
87
- })).rejects.toThrow('Subscription is required and must be specified as a string when creating consumer');
88
- });
89
-
90
- test('Not String Subscription', async () => {
91
- await expect(client.subscribe({
92
- topic: 'persistent://public/default/t1',
93
- subscription: 0,
94
- ackTimeoutMs: 10000,
95
- nAckRedeliverTimeoutMs: 60000,
96
- })).rejects.toThrow('Subscription is required and must be specified as a string when creating consumer');
97
- });
98
-
99
- test('Not Exist Tenant', async () => {
100
- await expect(client.subscribe({
101
- topic: 'persistent://no-tenant/namespace/topic',
102
- subscription: 'sub1',
103
- ackTimeoutMs: 10000,
104
- nAckRedeliverTimeoutMs: 60000,
105
- })).rejects.toThrow('Failed to create consumer: TopicNotFound');
106
- });
107
-
108
- test('Not Exist Namespace', async () => {
109
- await expect(client.subscribe({
110
- topic: 'persistent://public/no-namespace/topic',
111
- subscription: 'sub1',
112
- ackTimeoutMs: 10000,
113
- nAckRedeliverTimeoutMs: 60000,
114
- })).rejects.toThrow('Failed to create consumer: TopicNotFound');
115
- });
116
-
117
- test('Not Positive NAckRedeliverTimeout', async () => {
118
- await expect(client.subscribe({
119
- topic: 'persistent://public/default/t1',
120
- subscription: 'sub1',
121
- ackTimeoutMs: 10000,
122
- nAckRedeliverTimeoutMs: -12,
123
- })).rejects.toThrow('NAck timeout should be greater than or equal to zero');
124
- });
125
-
126
- test('Ack timeout less 10000', async () => {
127
- await expect(client.subscribe({
128
- topic: 'test-topic',
129
- subscription: 'sub1',
130
- subscriptionType: 'Shared',
131
- ackTimeoutMs: 100,
132
- })).rejects.toThrow('Ack timeout should be 0 or greater than or equal to 10000');
133
- });
134
-
135
- test('NAck timeout less 0', async () => {
136
- await expect(client.subscribe({
137
- topic: 'test-topic',
138
- subscription: 'sub1',
139
- subscriptionType: 'Shared',
140
- nAckRedeliverTimeoutMs: -1,
141
- })).rejects.toThrow('NAck timeout should be greater than or equal to zero');
142
- });
143
-
144
- test('Batch Receive Config Error', async () => {
145
- await expect(client.subscribe({
146
- topic: 'test-batch-receive-policy-error',
147
- subscription: 'sub1',
148
- subscriptionType: 'Shared',
149
- batchReceivePolicy: {
150
- maxNumMessages: -1,
151
- maxNumBytes: -1,
152
- timeoutMs: -1,
153
- },
154
- })).rejects.toThrow('At least one of maxNumMessages, maxNumBytes and timeoutMs must be specified.');
155
- });
156
- });
157
-
158
- describe('Close', () => {
159
- test('throws error on subsequent calls to close', async () => {
160
- const consumer = await client.subscribe({
161
- topic: 'persistent://public/default/my-topic',
162
- subscription: 'sub1',
163
- subscriptionType: 'Shared',
164
- // Test with listener since it changes the flow of close
165
- // and reproduces an issue
166
- listener() {},
167
- });
168
-
169
- await expect(consumer.close()).resolves.toEqual(null);
170
-
171
- await expect(consumer.close()).resolves.toEqual(null);
172
- });
173
- });
174
-
175
- describe('Features', () => {
176
- test('Batch index ack', async () => {
177
- const topicName = 'test-batch-index-ack';
178
- const producer = await client.createProducer({
179
- topic: topicName,
180
- batchingEnabled: true,
181
- batchingMaxMessages: 100,
182
- batchingMaxPublishDelayMs: 10000,
183
- });
184
-
185
- let consumer = await client.subscribe({
186
- topic: topicName,
187
- batchIndexAckEnabled: true,
188
- subscription: 'test-batch-index-ack',
189
- });
190
-
191
- // Make sure send 0~5 is a batch msg.
192
- for (let i = 0; i < 5; i += 1) {
193
- const msg = `my-message-${i}`;
194
- console.log(msg);
195
- producer.send({
196
- data: Buffer.from(msg),
197
- });
198
- }
199
- await producer.flush();
200
-
201
- // Receive msgs and just ack 0, 1 msgs
202
- const results = [];
203
- for (let i = 0; i < 5; i += 1) {
204
- const msg = await consumer.receive();
205
- results.push(msg);
206
- }
207
- expect(results.length).toEqual(5);
208
- for (let i = 0; i < 2; i += 1) {
209
- await consumer.acknowledge(results[i]);
210
- await new Promise((resolve) => setTimeout(resolve, 200));
211
- }
212
-
213
- // Restart consumer after, just receive 2~5 msg.
214
- await consumer.close();
215
- consumer = await client.subscribe({
216
- topic: topicName,
217
- batchIndexAckEnabled: true,
218
- subscription: 'test-batch-index-ack',
219
- });
220
- const results2 = [];
221
- for (let i = 2; i < 5; i += 1) {
222
- const msg = await consumer.receive();
223
- results2.push(msg);
224
- }
225
- expect(results2.length).toEqual(3);
226
- // assert no more msgs.
227
- await expect(consumer.receive(1000)).rejects.toThrow(
228
- 'Failed to receive message: TimeOut',
229
- );
230
- });
231
-
232
- test('Regex subscription', async () => {
233
- const topicName1 = 'persistent://public/default/regex-sub-1';
234
- const topicName2 = 'persistent://public/default/regex-sub-2';
235
- const topicName3 = 'non-persistent://public/default/regex-sub-3';
236
- const topicName4 = 'persistent://public/default/no-match-regex-sub-2';
237
- const producer1 = await client.createProducer({
238
- topic: topicName1,
239
- });
240
- const producer2 = await client.createProducer({
241
- topic: topicName2,
242
- });
243
- const producer3 = await client.createProducer({
244
- topic: topicName3,
245
- });
246
- const producer4 = await client.createProducer({
247
- topic: topicName4,
248
- });
249
-
250
- const consumer = await client.subscribe({
251
- topicsPattern: 'persistent://public/default/regex-sub.*',
252
- subscription: 'sub1',
253
- subscriptionType: 'Shared',
254
- regexSubscriptionMode: 'AllTopics',
255
- });
256
-
257
- const num = 10;
258
- for (let i = 0; i < num; i += 1) {
259
- const msg = `my-message-${i}`;
260
- await producer1.send({ data: Buffer.from(msg) });
261
- await producer2.send({ data: Buffer.from(msg) });
262
- await producer3.send({ data: Buffer.from(msg) });
263
- await producer4.send({ data: Buffer.from(msg) });
264
- }
265
- const results = [];
266
- for (let i = 0; i < 3 * num; i += 1) {
267
- const msg = await consumer.receive();
268
- results.push(msg.getData().toString());
269
- }
270
- expect(results.length).toEqual(3 * num);
271
- // assert no more msgs.
272
- await expect(consumer.receive(1000)).rejects.toThrow(
273
- 'Failed to receive message: TimeOut',
274
- );
275
- await producer1.close();
276
- await producer2.close();
277
- await producer3.close();
278
- await producer4.close();
279
- await consumer.close();
280
- });
281
-
282
- test('Dead Letter topic', async () => {
283
- const topicName = 'test-dead_letter_topic';
284
- const dlqTopicName = 'test-dead_letter_topic_customize';
285
- const producer = await client.createProducer({
286
- topic: topicName,
287
- });
288
-
289
- const maxRedeliverCountNum = 3;
290
- const consumer = await client.subscribe({
291
- topic: topicName,
292
- subscription: 'sub-1',
293
- subscriptionType: 'Shared',
294
- deadLetterPolicy: {
295
- deadLetterTopic: dlqTopicName,
296
- maxRedeliverCount: maxRedeliverCountNum,
297
- initialSubscriptionName: 'init-sub-1-dlq',
298
- },
299
- nAckRedeliverTimeoutMs: 50,
300
- });
301
-
302
- // Send messages.
303
- const sendNum = 5;
304
- const messages = [];
305
- for (let i = 0; i < sendNum; i += 1) {
306
- const msg = `my-message-${i}`;
307
- await producer.send({ data: Buffer.from(msg) });
308
- messages.push(msg);
309
- }
310
-
311
- // Redelivery all messages maxRedeliverCountNum time.
312
- let results = [];
313
- for (let i = 1; i <= maxRedeliverCountNum * sendNum + sendNum; i += 1) {
314
- const msg = await consumer.receive();
315
- results.push(msg);
316
- if (i % sendNum === 0) {
317
- results.forEach((message) => {
318
- console.log(`Redeliver message ${message.getData().toString()} ${i} times ${message.getRedeliveryCount()} redeliver Count`);
319
- consumer.negativeAcknowledge(message);
320
- });
321
- results = [];
322
- }
323
- }
324
- // assert no more msgs.
325
- await expect(consumer.receive(100)).rejects.toThrow(
326
- 'Failed to receive message: TimeOut',
327
- );
328
-
329
- const dlqConsumer = await client.subscribe({
330
- topic: dlqTopicName,
331
- subscription: 'sub-1',
332
- });
333
- const dlqResult = [];
334
- for (let i = 0; i < sendNum; i += 1) {
335
- const msg = await dlqConsumer.receive();
336
- dlqResult.push(msg.getData().toString());
337
- }
338
- expect(dlqResult).toEqual(messages);
339
-
340
- // assert no more msgs.
341
- await expect(dlqConsumer.receive(500)).rejects.toThrow(
342
- 'Failed to receive message: TimeOut',
343
- );
344
-
345
- producer.close();
346
- consumer.close();
347
- dlqConsumer.close();
348
- });
349
-
350
- test('Batch Receive by maxNumberMessages', async () => {
351
- const topicName = 'batch-receive-test-topic';
352
- const producer = await client.createProducer({
353
- topic: topicName,
354
- });
355
-
356
- const consumer = await client.subscribe({
357
- topic: topicName,
358
- subscription: 'sub1',
359
- subscriptionType: 'Shared',
360
- batchReceivePolicy: {
361
- maxNumMessages: 10,
362
- maxNumBytes: -1,
363
- timeoutMs: 500,
364
- },
365
- });
366
- const num = 10;
367
- const messages = [];
368
- for (let i = 0; i < num; i += 1) {
369
- const msg = `my-message-${i}`;
370
- await producer.send({ data: Buffer.from(msg) });
371
- messages.push(msg);
372
- }
373
-
374
- const receiveMessages = await consumer.batchReceive();
375
- expect(receiveMessages.length).toEqual(num);
376
- const results = [];
377
- for (let i = 0; i < receiveMessages.length; i += 1) {
378
- const msg = receiveMessages[i];
379
- console.log(msg.getData().toString());
380
- results.push(msg.getData().toString());
381
- }
382
- expect(results).toEqual(messages);
383
-
384
- // assert no more msgs.
385
- expect(await consumer.batchReceive()).toEqual([]);
386
-
387
- await producer.close();
388
- await consumer.close();
389
- });
390
-
391
- test('Batch Receive by timeOutMs', async () => {
392
- const topicName = 'batch-receive-test-topic-timeout';
393
- const producer = await client.createProducer({
394
- topic: topicName,
395
- });
396
-
397
- const consumer = await client.subscribe({
398
- topic: topicName,
399
- subscription: 'sub1',
400
- subscriptionType: 'Shared',
401
- batchReceivePolicy: {
402
- maxNumMessages: 100,
403
- maxNumBytes: -1,
404
- timeoutMs: 500,
405
- },
406
- });
407
- // just send 10 message waite trigger timeout.
408
- const num = 10;
409
- const messages = [];
410
- for (let i = 0; i < num; i += 1) {
411
- const msg = `my-message-${i}`;
412
- await producer.send({ data: Buffer.from(msg) });
413
- messages.push(msg);
414
- }
415
-
416
- const receiveMessages = await consumer.batchReceive();
417
- expect(receiveMessages.length).toEqual(num);
418
- const results = [];
419
- for (let i = 0; i < receiveMessages.length; i += 1) {
420
- const msg = receiveMessages[i];
421
- console.log(msg.getData().toString());
422
- results.push(msg.getData().toString());
423
- }
424
- expect(results).toEqual(messages);
425
-
426
- // assert no more msgs.
427
- expect(await consumer.batchReceive()).toEqual([]);
428
-
429
- await producer.close();
430
- await consumer.close();
431
- });
432
- });
433
- });
434
- })();
@@ -1,35 +0,0 @@
1
- #!/bin/bash
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- # NOTE: This script should only run inside a Node.js docker container.
22
- # See ./load-test.sh for details.
23
- set -ex
24
-
25
- # Create an empty directory to test
26
- mkdir -p /app && cd /app
27
- tar zxf /pulsar-client-node/pulsar-client-node.tar.gz
28
-
29
- # Use the existing Pulsar.node built in a specific container
30
- mkdir -p lib/binding
31
- cp /pulsar-client-node/build/Release/pulsar.node lib/binding/
32
- npm install
33
-
34
- # Test if Pulsar.node can be loaded
35
- node pkg/load_test.js