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.
- package/.idea/aws.xml +18 -0
- package/.idea/codeStyles/Project.xml +7 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +7 -0
- package/.idea/modules.xml +9 -0
- package/.idea/pulsar-client-node.iml +46 -0
- package/.idea/pulsar_client_node.iml +8 -0
- package/.idea/vcs.xml +6 -0
- package/index.d.ts +17 -0
- package/package.json +1 -1
- package/src/Client.cc +2 -1
- package/src/Client.h +1 -0
- package/src/ConsumerConfig.cc +66 -0
- package/src/cert.pem +3278 -0
- package/.clang-format +0 -26
- package/.eslintignore +0 -21
- package/.eslintrc.json +0 -22
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -85
- package/.github/workflows/ci-build-release-napi.yml +0 -211
- package/.github/workflows/ci-pr-validation.yml +0 -334
- package/build-support/download-release-artifacts.py +0 -77
- package/build-support/generate-source-archive.sh +0 -28
- package/build-support/pulsar-test-container-start.sh +0 -43
- package/build-support/pulsar-test-service-start.sh +0 -39
- package/build-support/pulsar-test-service-stop.sh +0 -32
- package/build-support/sign-files.sh +0 -32
- package/build-support/stage-release.sh +0 -44
- package/docs/release-process.md +0 -291
- package/examples/certificate/private-key.client-rsa.pem +0 -27
- package/examples/certificate/public-key.client-rsa.pem +0 -9
- package/examples/consumer-schema.js +0 -66
- package/examples/consumer.js +0 -46
- package/examples/consumer_listener.js +0 -44
- package/examples/consumer_tls_auth.js +0 -51
- package/examples/consummer_token_auth.js +0 -50
- package/examples/consummer_token_auth_supplier.js +0 -56
- package/examples/custom_logger.js +0 -60
- package/examples/encryption-consumer.js +0 -47
- package/examples/encryption-producer.js +0 -50
- package/examples/encryption-reader.js +0 -44
- package/examples/producer-schema.js +0 -76
- package/examples/producer.js +0 -48
- package/examples/producer_tls_auth.js +0 -52
- package/examples/producer_token_auth.js +0 -48
- package/examples/producer_token_auth_supplier.js +0 -53
- package/examples/reader.js +0 -43
- package/examples/reader_listener.js +0 -37
- package/license-checker-config.json +0 -43
- package/license-header.txt +0 -16
- package/perf/perf_consumer.js +0 -103
- package/perf/perf_producer.js +0 -118
- package/pkg/linux/Dockerfile_linux_glibc +0 -31
- package/pkg/linux/Dockerfile_linux_musl +0 -32
- package/pkg/linux/build-napi-inside-docker.sh +0 -31
- package/pkg/linux/download-cpp-client.sh +0 -65
- package/pkg/load_test.js +0 -34
- package/pkg/mac/download-cpp-client.sh +0 -36
- package/pkg/windows/download-cpp-client.bat +0 -12
- package/tests/certificate/private-key.client-rsa.pem +0 -27
- package/tests/certificate/public-key.client-rsa.pem +0 -9
- package/tests/certificate/server.crt +0 -20
- package/tests/certificate/server.key +0 -28
- package/tests/client.test.js +0 -122
- package/tests/conf/standalone.conf +0 -308
- package/tests/consumer.test.js +0 -434
- package/tests/docker-load-test.sh +0 -35
- package/tests/end_to_end.test.js +0 -1447
- package/tests/http_utils.js +0 -45
- package/tests/load-test.sh +0 -43
- package/tests/producer.test.js +0 -160
- package/tests/reader.test.js +0 -175
- package/tests/run-unit-tests.sh +0 -35
- package/tsconfig.json +0 -22
- package/tslint.json +0 -9
- package/tstest.ts +0 -408
- package/typedoc.json +0 -15
package/tests/end_to_end.test.js
DELETED
|
@@ -1,1447 +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 lodash = require('lodash');
|
|
21
|
-
const Pulsar = require('../index');
|
|
22
|
-
|
|
23
|
-
(() => {
|
|
24
|
-
describe('End To End', () => {
|
|
25
|
-
test.each([
|
|
26
|
-
{ serviceUrl: 'pulsar://localhost:6650', listenerName: undefined },
|
|
27
|
-
{ serviceUrl: 'pulsar+ssl://localhost:6651', listenerName: 'localhost6651' },
|
|
28
|
-
{ serviceUrl: 'http://localhost:8080', listenerName: undefined },
|
|
29
|
-
{ serviceUrl: 'https://localhost:8443', listenerName: 'localhost8443' },
|
|
30
|
-
])('Produce/Consume to $serviceUrl', async ({ serviceUrl, listenerName }) => {
|
|
31
|
-
const client = new Pulsar.Client({
|
|
32
|
-
serviceUrl,
|
|
33
|
-
tlsTrustCertsFilePath: `${__dirname}/certificate/server.crt`,
|
|
34
|
-
operationTimeoutSeconds: 30,
|
|
35
|
-
connectionTimeoutMs: 20000,
|
|
36
|
-
listenerName,
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const topic = 'persistent://public/default/produce-consume';
|
|
40
|
-
const producer = await client.createProducer({
|
|
41
|
-
topic,
|
|
42
|
-
sendTimeoutMs: 30000,
|
|
43
|
-
batchingEnabled: true,
|
|
44
|
-
});
|
|
45
|
-
expect(producer).not.toBeNull();
|
|
46
|
-
|
|
47
|
-
const consumer = await client.subscribe({
|
|
48
|
-
topic,
|
|
49
|
-
subscription: 'sub1',
|
|
50
|
-
ackTimeoutMs: 10000,
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
expect(consumer).not.toBeNull();
|
|
54
|
-
|
|
55
|
-
const messages = [];
|
|
56
|
-
for (let i = 0; i < 10; i += 1) {
|
|
57
|
-
const msg = `my-message-${i}`;
|
|
58
|
-
producer.send({
|
|
59
|
-
data: Buffer.from(msg),
|
|
60
|
-
});
|
|
61
|
-
messages.push(msg);
|
|
62
|
-
}
|
|
63
|
-
await producer.flush();
|
|
64
|
-
|
|
65
|
-
const results = [];
|
|
66
|
-
for (let i = 0; i < 10; i += 1) {
|
|
67
|
-
const msg = await consumer.receive();
|
|
68
|
-
consumer.acknowledge(msg);
|
|
69
|
-
results.push(msg.getData().toString());
|
|
70
|
-
}
|
|
71
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
72
|
-
|
|
73
|
-
await producer.close();
|
|
74
|
-
await consumer.close();
|
|
75
|
-
await client.close();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('negativeAcknowledge', async () => {
|
|
79
|
-
const client = new Pulsar.Client({
|
|
80
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
81
|
-
operationTimeoutSeconds: 30,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const topic = 'persistent://public/default/produce-consume';
|
|
85
|
-
const producer = await client.createProducer({
|
|
86
|
-
topic,
|
|
87
|
-
sendTimeoutMs: 30000,
|
|
88
|
-
batchingEnabled: true,
|
|
89
|
-
});
|
|
90
|
-
expect(producer).not.toBeNull();
|
|
91
|
-
|
|
92
|
-
const consumer = await client.subscribe({
|
|
93
|
-
topic,
|
|
94
|
-
subscription: 'sub1',
|
|
95
|
-
ackTimeoutMs: 10000,
|
|
96
|
-
nAckRedeliverTimeoutMs: 1000,
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
expect(consumer).not.toBeNull();
|
|
100
|
-
|
|
101
|
-
const message = 'my-message';
|
|
102
|
-
producer.send({
|
|
103
|
-
data: Buffer.from(message),
|
|
104
|
-
});
|
|
105
|
-
await producer.flush();
|
|
106
|
-
|
|
107
|
-
const results = [];
|
|
108
|
-
const msg = await consumer.receive();
|
|
109
|
-
results.push(msg.getData().toString());
|
|
110
|
-
consumer.negativeAcknowledge(msg);
|
|
111
|
-
|
|
112
|
-
const msg2 = await consumer.receive();
|
|
113
|
-
results.push(msg2.getData().toString());
|
|
114
|
-
consumer.acknowledge(msg2);
|
|
115
|
-
|
|
116
|
-
await expect(consumer.receive(1000)).rejects.toThrow(
|
|
117
|
-
'Failed to receive message: TimeOut',
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
expect(results).toEqual([message, message]);
|
|
121
|
-
|
|
122
|
-
await producer.close();
|
|
123
|
-
await consumer.close();
|
|
124
|
-
await client.close();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('getRedeliveryCount', async () => {
|
|
128
|
-
const client = new Pulsar.Client({
|
|
129
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
130
|
-
operationTimeoutSeconds: 30,
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const topic = 'persistent://public/default/produce-consume';
|
|
134
|
-
const producer = await client.createProducer({
|
|
135
|
-
topic,
|
|
136
|
-
sendTimeoutMs: 30000,
|
|
137
|
-
batchingEnabled: true,
|
|
138
|
-
});
|
|
139
|
-
expect(producer).not.toBeNull();
|
|
140
|
-
|
|
141
|
-
const consumer = await client.subscribe({
|
|
142
|
-
topic,
|
|
143
|
-
subscriptionType: 'Shared',
|
|
144
|
-
subscription: 'sub1',
|
|
145
|
-
ackTimeoutMs: 10000,
|
|
146
|
-
nAckRedeliverTimeoutMs: 100,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
expect(consumer).not.toBeNull();
|
|
150
|
-
|
|
151
|
-
const message = 'my-message';
|
|
152
|
-
producer.send({
|
|
153
|
-
data: Buffer.from(message),
|
|
154
|
-
});
|
|
155
|
-
await producer.flush();
|
|
156
|
-
|
|
157
|
-
let redeliveryCount;
|
|
158
|
-
let msg;
|
|
159
|
-
for (let index = 0; index < 3; index += 1) {
|
|
160
|
-
msg = await consumer.receive();
|
|
161
|
-
redeliveryCount = msg.getRedeliveryCount();
|
|
162
|
-
consumer.negativeAcknowledge(msg);
|
|
163
|
-
}
|
|
164
|
-
expect(redeliveryCount).toBe(2);
|
|
165
|
-
consumer.acknowledge(msg);
|
|
166
|
-
|
|
167
|
-
await producer.close();
|
|
168
|
-
await consumer.close();
|
|
169
|
-
await client.close();
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('Produce/Consume Listener', async () => {
|
|
173
|
-
const client = new Pulsar.Client({
|
|
174
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
175
|
-
operationTimeoutSeconds: 30,
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
const topic = 'persistent://public/default/produce-consume-listener';
|
|
179
|
-
const producer = await client.createProducer({
|
|
180
|
-
topic,
|
|
181
|
-
sendTimeoutMs: 30000,
|
|
182
|
-
batchingEnabled: true,
|
|
183
|
-
});
|
|
184
|
-
expect(producer).not.toBeNull();
|
|
185
|
-
|
|
186
|
-
let finish;
|
|
187
|
-
const results = [];
|
|
188
|
-
const finishPromise = new Promise((resolve) => {
|
|
189
|
-
finish = resolve;
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
const consumer = await client.subscribe({
|
|
193
|
-
topic,
|
|
194
|
-
subscription: 'sub1',
|
|
195
|
-
ackTimeoutMs: 10000,
|
|
196
|
-
listener: (message, messageConsumer) => {
|
|
197
|
-
const data = message.getData().toString();
|
|
198
|
-
results.push(data);
|
|
199
|
-
messageConsumer.acknowledge(message);
|
|
200
|
-
if (results.length === 10) finish();
|
|
201
|
-
},
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
expect(consumer).not.toBeNull();
|
|
205
|
-
|
|
206
|
-
const messages = [];
|
|
207
|
-
for (let i = 0; i < 10; i += 1) {
|
|
208
|
-
const msg = `my-message-${i}`;
|
|
209
|
-
producer.send({
|
|
210
|
-
data: Buffer.from(msg),
|
|
211
|
-
});
|
|
212
|
-
messages.push(msg);
|
|
213
|
-
}
|
|
214
|
-
await producer.flush();
|
|
215
|
-
|
|
216
|
-
await finishPromise;
|
|
217
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
218
|
-
|
|
219
|
-
await producer.close();
|
|
220
|
-
await consumer.close();
|
|
221
|
-
await client.close();
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
test('Produce/Read Listener', async () => {
|
|
225
|
-
const client = new Pulsar.Client({
|
|
226
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
227
|
-
operationTimeoutSeconds: 30,
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
const topic = 'persistent://public/default/produce-read-listener';
|
|
231
|
-
const producer = await client.createProducer({
|
|
232
|
-
topic,
|
|
233
|
-
sendTimeoutMs: 30000,
|
|
234
|
-
batchingEnabled: true,
|
|
235
|
-
});
|
|
236
|
-
expect(producer).not.toBeNull();
|
|
237
|
-
|
|
238
|
-
let finish;
|
|
239
|
-
const results = [];
|
|
240
|
-
const finishPromise = new Promise((resolve) => {
|
|
241
|
-
finish = resolve;
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
const reader = await client.createReader({
|
|
245
|
-
topic,
|
|
246
|
-
startMessageId: Pulsar.MessageId.latest(),
|
|
247
|
-
listener: (message) => {
|
|
248
|
-
const data = message.getData().toString();
|
|
249
|
-
results.push(data);
|
|
250
|
-
if (results.length === 10) finish();
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
expect(reader).not.toBeNull();
|
|
255
|
-
|
|
256
|
-
const messages = [];
|
|
257
|
-
for (let i = 0; i < 10; i += 1) {
|
|
258
|
-
const msg = `my-message-${i}`;
|
|
259
|
-
producer.send({
|
|
260
|
-
data: Buffer.from(msg),
|
|
261
|
-
});
|
|
262
|
-
messages.push(msg);
|
|
263
|
-
}
|
|
264
|
-
await producer.flush();
|
|
265
|
-
|
|
266
|
-
await finishPromise;
|
|
267
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
268
|
-
|
|
269
|
-
await producer.close();
|
|
270
|
-
await reader.close();
|
|
271
|
-
await client.close();
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
test('Share consumers with message listener', async () => {
|
|
275
|
-
const client = new Pulsar.Client({
|
|
276
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
277
|
-
operationTimeoutSeconds: 30,
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
const topic = 'test-shared-consumer-listener';
|
|
281
|
-
const producer = await client.createProducer({
|
|
282
|
-
topic,
|
|
283
|
-
batchingEnabled: false,
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
for (let i = 0; i < 100; i += 1) {
|
|
287
|
-
await producer.send(i);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
let consumer1Recv = 0;
|
|
291
|
-
|
|
292
|
-
const consumer1 = await client.subscribe({
|
|
293
|
-
topic,
|
|
294
|
-
subscription: 'sub',
|
|
295
|
-
subscriptionType: 'Shared',
|
|
296
|
-
subscriptionInitialPosition: 'Earliest',
|
|
297
|
-
receiverQueueSize: 10,
|
|
298
|
-
listener: async (message, messageConsumer) => {
|
|
299
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
300
|
-
consumer1Recv += 1;
|
|
301
|
-
await messageConsumer.acknowledge(message);
|
|
302
|
-
},
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
const consumer2 = await client.subscribe({
|
|
306
|
-
topic,
|
|
307
|
-
subscription: 'sub',
|
|
308
|
-
subscriptionType: 'Shared',
|
|
309
|
-
subscriptionInitialPosition: 'Earliest',
|
|
310
|
-
receiverQueueSize: 10,
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
let consumer2Recv = 0;
|
|
314
|
-
while (true) {
|
|
315
|
-
try {
|
|
316
|
-
const msg = await consumer2.receive(3000);
|
|
317
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
318
|
-
consumer2Recv += 1;
|
|
319
|
-
await consumer2.acknowledge(msg);
|
|
320
|
-
} catch (err) {
|
|
321
|
-
break;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// Ensure that each consumer receives at least 1 times (greater than and not equal)
|
|
326
|
-
// the receiver queue size messages.
|
|
327
|
-
// This way any of the consumers will not immediately empty all messages of a topic.
|
|
328
|
-
expect(consumer1Recv).toBeGreaterThan(10);
|
|
329
|
-
expect(consumer2Recv).toBeGreaterThan(10);
|
|
330
|
-
|
|
331
|
-
await consumer1.close();
|
|
332
|
-
await consumer2.close();
|
|
333
|
-
await producer.close();
|
|
334
|
-
await client.close();
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
test('Share readers with message listener', async () => {
|
|
338
|
-
const client = new Pulsar.Client({
|
|
339
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
340
|
-
operationTimeoutSeconds: 30,
|
|
341
|
-
});
|
|
342
|
-
|
|
343
|
-
const topic = 'test-shared-reader-listener';
|
|
344
|
-
const producer = await client.createProducer({
|
|
345
|
-
topic,
|
|
346
|
-
batchingEnabled: false,
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
for (let i = 0; i < 100; i += 1) {
|
|
350
|
-
await producer.send(i);
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
let reader1Recv = 0;
|
|
354
|
-
|
|
355
|
-
const reader1 = await client.createReader({
|
|
356
|
-
topic,
|
|
357
|
-
startMessageId: Pulsar.MessageId.earliest(),
|
|
358
|
-
receiverQueueSize: 10,
|
|
359
|
-
listener: async (message, reader) => {
|
|
360
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
361
|
-
reader1Recv += 1;
|
|
362
|
-
},
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
const reader2 = await client.createReader({
|
|
366
|
-
topic,
|
|
367
|
-
startMessageId: Pulsar.MessageId.earliest(),
|
|
368
|
-
receiverQueueSize: 10,
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
let reader2Recv = 0;
|
|
372
|
-
|
|
373
|
-
while (reader2.hasNext()) {
|
|
374
|
-
await reader2.readNext();
|
|
375
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
376
|
-
reader2Recv += 1;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Ensure that each reader receives at least 1 times (greater than and not equal)
|
|
380
|
-
// the receiver queue size messages.
|
|
381
|
-
// This way any of the readers will not immediately empty all messages of a topic.
|
|
382
|
-
expect(reader1Recv).toBeGreaterThan(10);
|
|
383
|
-
expect(reader2Recv).toBeGreaterThan(10);
|
|
384
|
-
|
|
385
|
-
await reader1.close();
|
|
386
|
-
await reader2.close();
|
|
387
|
-
await producer.close();
|
|
388
|
-
await client.close();
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
test('Message Listener error handling', async () => {
|
|
392
|
-
const client = new Pulsar.Client({
|
|
393
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
394
|
-
});
|
|
395
|
-
let syncFinsh;
|
|
396
|
-
const syncPromise = new Promise((resolve) => {
|
|
397
|
-
syncFinsh = resolve;
|
|
398
|
-
});
|
|
399
|
-
let asyncFinsh;
|
|
400
|
-
const asyncPromise = new Promise((resolve) => {
|
|
401
|
-
asyncFinsh = resolve;
|
|
402
|
-
});
|
|
403
|
-
Pulsar.Client.setLogHandler((level, file, line, message) => {
|
|
404
|
-
if (level === 3) { // should be error level
|
|
405
|
-
if (message.includes('consumer1 callback expected error')) {
|
|
406
|
-
syncFinsh();
|
|
407
|
-
}
|
|
408
|
-
if (message.includes('consumer2 callback expected error')) {
|
|
409
|
-
asyncFinsh();
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
const topic = 'test-error-listener';
|
|
415
|
-
const producer = await client.createProducer({
|
|
416
|
-
topic,
|
|
417
|
-
batchingEnabled: false,
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
await producer.send('test-message');
|
|
421
|
-
|
|
422
|
-
const consumer1 = await client.subscribe({
|
|
423
|
-
topic,
|
|
424
|
-
subscription: 'sync',
|
|
425
|
-
subscriptionType: 'Shared',
|
|
426
|
-
subscriptionInitialPosition: 'Earliest',
|
|
427
|
-
listener: (message, messageConsumer) => {
|
|
428
|
-
throw new Error('consumer1 callback expected error');
|
|
429
|
-
},
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
const consumer2 = await client.subscribe({
|
|
433
|
-
topic,
|
|
434
|
-
subscription: 'async',
|
|
435
|
-
subscriptionType: 'Shared',
|
|
436
|
-
subscriptionInitialPosition: 'Earliest',
|
|
437
|
-
listener: async (message, messageConsumer) => {
|
|
438
|
-
throw new Error('consumer2 callback expected error');
|
|
439
|
-
},
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
await syncPromise;
|
|
443
|
-
await asyncPromise;
|
|
444
|
-
|
|
445
|
-
await consumer1.close();
|
|
446
|
-
await consumer2.close();
|
|
447
|
-
await producer.close();
|
|
448
|
-
await client.close();
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
test('acknowledgeCumulative', async () => {
|
|
452
|
-
const client = new Pulsar.Client({
|
|
453
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
454
|
-
operationTimeoutSeconds: 30,
|
|
455
|
-
});
|
|
456
|
-
|
|
457
|
-
const topic = 'persistent://public/default/acknowledgeCumulative';
|
|
458
|
-
const producer = await client.createProducer({
|
|
459
|
-
topic,
|
|
460
|
-
sendTimeoutMs: 30000,
|
|
461
|
-
batchingEnabled: true,
|
|
462
|
-
});
|
|
463
|
-
expect(producer).not.toBeNull();
|
|
464
|
-
|
|
465
|
-
const consumer = await client.subscribe({
|
|
466
|
-
topic,
|
|
467
|
-
subscription: 'sub1',
|
|
468
|
-
ackTimeoutMs: 10000,
|
|
469
|
-
});
|
|
470
|
-
expect(consumer).not.toBeNull();
|
|
471
|
-
|
|
472
|
-
const messages = [];
|
|
473
|
-
for (let i = 0; i < 10; i += 1) {
|
|
474
|
-
const msg = `my-message-${i}`;
|
|
475
|
-
producer.send({
|
|
476
|
-
data: Buffer.from(msg),
|
|
477
|
-
});
|
|
478
|
-
messages.push(msg);
|
|
479
|
-
}
|
|
480
|
-
await producer.flush();
|
|
481
|
-
|
|
482
|
-
for (let i = 0; i < 10; i += 1) {
|
|
483
|
-
const msg = await consumer.receive();
|
|
484
|
-
if (i === 9) {
|
|
485
|
-
consumer.acknowledgeCumulative(msg);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
await expect(consumer.receive(1000)).rejects.toThrow(
|
|
490
|
-
'Failed to receive message: TimeOut',
|
|
491
|
-
);
|
|
492
|
-
|
|
493
|
-
await producer.close();
|
|
494
|
-
await consumer.close();
|
|
495
|
-
await client.close();
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
test('subscriptionInitialPosition', async () => {
|
|
499
|
-
const client = new Pulsar.Client({
|
|
500
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
501
|
-
operationTimeoutSeconds: 30,
|
|
502
|
-
});
|
|
503
|
-
|
|
504
|
-
const topic = 'persistent://public/default/subscriptionInitialPosition';
|
|
505
|
-
const producer = await client.createProducer({
|
|
506
|
-
topic,
|
|
507
|
-
sendTimeoutMs: 30000,
|
|
508
|
-
batchingEnabled: false,
|
|
509
|
-
});
|
|
510
|
-
expect(producer).not.toBeNull();
|
|
511
|
-
|
|
512
|
-
const messages = [];
|
|
513
|
-
for (let i = 0; i < 2; i += 1) {
|
|
514
|
-
const msg = `my-message-${i}`;
|
|
515
|
-
producer.send({
|
|
516
|
-
data: Buffer.from(msg),
|
|
517
|
-
});
|
|
518
|
-
messages.push(msg);
|
|
519
|
-
}
|
|
520
|
-
await producer.flush();
|
|
521
|
-
|
|
522
|
-
const latestConsumer = await client.subscribe({
|
|
523
|
-
topic,
|
|
524
|
-
subscription: 'latestSub',
|
|
525
|
-
subscriptionInitialPosition: 'Latest',
|
|
526
|
-
});
|
|
527
|
-
expect(latestConsumer).not.toBeNull();
|
|
528
|
-
|
|
529
|
-
const earliestConsumer = await client.subscribe({
|
|
530
|
-
topic,
|
|
531
|
-
subscription: 'earliestSub',
|
|
532
|
-
subscriptionInitialPosition: 'Earliest',
|
|
533
|
-
});
|
|
534
|
-
expect(earliestConsumer).not.toBeNull();
|
|
535
|
-
|
|
536
|
-
for (let i = 2; i < 4; i += 1) {
|
|
537
|
-
const msg = `my-message-${i}`;
|
|
538
|
-
producer.send({
|
|
539
|
-
data: Buffer.from(msg),
|
|
540
|
-
});
|
|
541
|
-
messages.push(msg);
|
|
542
|
-
}
|
|
543
|
-
await producer.flush();
|
|
544
|
-
|
|
545
|
-
const latestResults = [];
|
|
546
|
-
const earliestResults = [];
|
|
547
|
-
for (let i = 0; i < 4; i += 1) {
|
|
548
|
-
if (i < 2) {
|
|
549
|
-
const latestMsg = await latestConsumer.receive(5000);
|
|
550
|
-
latestConsumer.acknowledge(latestMsg);
|
|
551
|
-
latestResults.push(latestMsg.getData().toString());
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
const earliestMsg = await earliestConsumer.receive(5000);
|
|
555
|
-
earliestConsumer.acknowledge(earliestMsg);
|
|
556
|
-
earliestResults.push(earliestMsg.getData().toString());
|
|
557
|
-
}
|
|
558
|
-
expect(lodash.difference(messages, latestResults)).toEqual(['my-message-0', 'my-message-1']);
|
|
559
|
-
expect(lodash.difference(messages, earliestResults)).toEqual([]);
|
|
560
|
-
|
|
561
|
-
await producer.close();
|
|
562
|
-
await latestConsumer.close();
|
|
563
|
-
await earliestConsumer.close();
|
|
564
|
-
await client.close();
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
test('Produce/Read', async () => {
|
|
568
|
-
const client = new Pulsar.Client({
|
|
569
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
570
|
-
operationTimeoutSeconds: 30,
|
|
571
|
-
});
|
|
572
|
-
expect(client).not.toBeNull();
|
|
573
|
-
|
|
574
|
-
const topic = 'persistent://public/default/produce-read';
|
|
575
|
-
const producer = await client.createProducer({
|
|
576
|
-
topic,
|
|
577
|
-
sendTimeoutMs: 30000,
|
|
578
|
-
batchingEnabled: true,
|
|
579
|
-
});
|
|
580
|
-
expect(producer).not.toBeNull();
|
|
581
|
-
|
|
582
|
-
const reader = await client.createReader({
|
|
583
|
-
topic,
|
|
584
|
-
startMessageId: Pulsar.MessageId.latest(),
|
|
585
|
-
});
|
|
586
|
-
expect(reader).not.toBeNull();
|
|
587
|
-
|
|
588
|
-
const messages = [];
|
|
589
|
-
for (let i = 0; i < 10; i += 1) {
|
|
590
|
-
const msg = `my-message-${i}`;
|
|
591
|
-
producer.send({
|
|
592
|
-
data: Buffer.from(msg),
|
|
593
|
-
});
|
|
594
|
-
messages.push(msg);
|
|
595
|
-
}
|
|
596
|
-
await producer.flush();
|
|
597
|
-
|
|
598
|
-
expect(reader.hasNext()).toBe(true);
|
|
599
|
-
|
|
600
|
-
const results = [];
|
|
601
|
-
for (let i = 0; i < 10; i += 1) {
|
|
602
|
-
const msg = await reader.readNext();
|
|
603
|
-
results.push(msg.getData().toString());
|
|
604
|
-
}
|
|
605
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
606
|
-
|
|
607
|
-
expect(reader.hasNext()).toBe(false);
|
|
608
|
-
|
|
609
|
-
await producer.close();
|
|
610
|
-
await reader.close();
|
|
611
|
-
await client.close();
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
test('Produce-Delayed/Consume', async () => {
|
|
615
|
-
const client = new Pulsar.Client({
|
|
616
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
617
|
-
operationTimeoutSeconds: 30,
|
|
618
|
-
});
|
|
619
|
-
expect(client).not.toBeNull();
|
|
620
|
-
|
|
621
|
-
const topic = 'persistent://public/default/produce-read-delayed';
|
|
622
|
-
const producer = await client.createProducer({
|
|
623
|
-
topic,
|
|
624
|
-
sendTimeoutMs: 30000,
|
|
625
|
-
batchingEnabled: true,
|
|
626
|
-
});
|
|
627
|
-
expect(producer).not.toBeNull();
|
|
628
|
-
|
|
629
|
-
const consumer = await client.subscribe({
|
|
630
|
-
topic,
|
|
631
|
-
subscription: 'sub',
|
|
632
|
-
subscriptionType: 'Shared',
|
|
633
|
-
});
|
|
634
|
-
expect(consumer).not.toBeNull();
|
|
635
|
-
|
|
636
|
-
const messages = [];
|
|
637
|
-
const time = (new Date()).getTime();
|
|
638
|
-
for (let i = 0; i < 5; i += 1) {
|
|
639
|
-
const msg = `my-message-${i}`;
|
|
640
|
-
producer.send({
|
|
641
|
-
data: Buffer.from(msg),
|
|
642
|
-
deliverAfter: 3000,
|
|
643
|
-
});
|
|
644
|
-
messages.push(msg);
|
|
645
|
-
}
|
|
646
|
-
for (let i = 5; i < 10; i += 1) {
|
|
647
|
-
const msg = `my-message-${i}`;
|
|
648
|
-
producer.send({
|
|
649
|
-
data: Buffer.from(msg),
|
|
650
|
-
deliverAt: (new Date()).getTime() + 3000,
|
|
651
|
-
});
|
|
652
|
-
messages.push(msg);
|
|
653
|
-
}
|
|
654
|
-
await producer.flush();
|
|
655
|
-
|
|
656
|
-
const results = [];
|
|
657
|
-
for (let i = 0; i < 10; i += 1) {
|
|
658
|
-
const msg = await consumer.receive();
|
|
659
|
-
results.push(msg.getData().toString());
|
|
660
|
-
consumer.acknowledge(msg);
|
|
661
|
-
}
|
|
662
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
663
|
-
expect((new Date()).getTime() - time).toBeGreaterThan(3000);
|
|
664
|
-
|
|
665
|
-
await producer.close();
|
|
666
|
-
await consumer.close();
|
|
667
|
-
await client.close();
|
|
668
|
-
});
|
|
669
|
-
|
|
670
|
-
test('Produce/Consume/Unsubscribe', async () => {
|
|
671
|
-
const client = new Pulsar.Client({
|
|
672
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
673
|
-
operationTimeoutSeconds: 30,
|
|
674
|
-
});
|
|
675
|
-
|
|
676
|
-
const topic = 'persistent://public/default/produce-consume-unsubscribe';
|
|
677
|
-
const producer = await client.createProducer({
|
|
678
|
-
topic,
|
|
679
|
-
sendTimeoutMs: 30000,
|
|
680
|
-
batchingEnabled: true,
|
|
681
|
-
});
|
|
682
|
-
expect(producer).not.toBeNull();
|
|
683
|
-
|
|
684
|
-
const consumer = await client.subscribe({
|
|
685
|
-
topic,
|
|
686
|
-
subscription: 'sub1',
|
|
687
|
-
ackTimeoutMs: 10000,
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
expect(consumer).not.toBeNull();
|
|
691
|
-
|
|
692
|
-
const messages = [];
|
|
693
|
-
for (let i = 0; i < 10; i += 1) {
|
|
694
|
-
const msg = `my-message-${i}`;
|
|
695
|
-
producer.send({
|
|
696
|
-
data: Buffer.from(msg),
|
|
697
|
-
});
|
|
698
|
-
messages.push(msg);
|
|
699
|
-
}
|
|
700
|
-
await producer.flush();
|
|
701
|
-
|
|
702
|
-
const results = [];
|
|
703
|
-
for (let i = 0; i < 10; i += 1) {
|
|
704
|
-
const msg = await consumer.receive();
|
|
705
|
-
consumer.acknowledge(msg);
|
|
706
|
-
results.push(msg.getData().toString());
|
|
707
|
-
}
|
|
708
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
709
|
-
|
|
710
|
-
await consumer.unsubscribe();
|
|
711
|
-
producer.send({ data: Buffer.from('drop') });
|
|
712
|
-
await producer.flush();
|
|
713
|
-
|
|
714
|
-
const consumer2 = await client.subscribe({
|
|
715
|
-
topic,
|
|
716
|
-
subscription: 'sub1',
|
|
717
|
-
ackTimeoutMs: 10000,
|
|
718
|
-
});
|
|
719
|
-
|
|
720
|
-
const testData = 'success';
|
|
721
|
-
producer.send({ data: Buffer.from(testData) });
|
|
722
|
-
await producer.flush();
|
|
723
|
-
|
|
724
|
-
const msg = await consumer2.receive();
|
|
725
|
-
consumer2.acknowledge(msg);
|
|
726
|
-
expect(msg.getData().toString()).toBe(testData);
|
|
727
|
-
|
|
728
|
-
await consumer2.close();
|
|
729
|
-
await producer.close();
|
|
730
|
-
await client.close();
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
test('Produce/Read (Compression)', async () => {
|
|
734
|
-
const client = new Pulsar.Client({
|
|
735
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
736
|
-
operationTimeoutSeconds: 30,
|
|
737
|
-
});
|
|
738
|
-
expect(client).not.toBeNull();
|
|
739
|
-
|
|
740
|
-
const topic = 'persistent://public/default/produce-read-compression';
|
|
741
|
-
const producer = await client.createProducer({
|
|
742
|
-
topic,
|
|
743
|
-
sendTimeoutMs: 30000,
|
|
744
|
-
batchingEnabled: true,
|
|
745
|
-
compressionType: 'ZSTD',
|
|
746
|
-
});
|
|
747
|
-
expect(producer).not.toBeNull();
|
|
748
|
-
|
|
749
|
-
const reader = await client.createReader({
|
|
750
|
-
topic,
|
|
751
|
-
startMessageId: Pulsar.MessageId.latest(),
|
|
752
|
-
});
|
|
753
|
-
expect(reader).not.toBeNull();
|
|
754
|
-
|
|
755
|
-
const messages = [];
|
|
756
|
-
for (let i = 0; i < 10; i += 1) {
|
|
757
|
-
const msg = `my-message-${i}`;
|
|
758
|
-
producer.send({
|
|
759
|
-
data: Buffer.from(msg),
|
|
760
|
-
});
|
|
761
|
-
messages.push(msg);
|
|
762
|
-
}
|
|
763
|
-
await producer.flush();
|
|
764
|
-
|
|
765
|
-
expect(reader.hasNext()).toBe(true);
|
|
766
|
-
|
|
767
|
-
const results = [];
|
|
768
|
-
for (let i = 0; i < 10; i += 1) {
|
|
769
|
-
const msg = await reader.readNext();
|
|
770
|
-
results.push(msg.getData().toString());
|
|
771
|
-
}
|
|
772
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
773
|
-
|
|
774
|
-
expect(reader.hasNext()).toBe(false);
|
|
775
|
-
|
|
776
|
-
await producer.close();
|
|
777
|
-
await reader.close();
|
|
778
|
-
await client.close();
|
|
779
|
-
});
|
|
780
|
-
|
|
781
|
-
test('Produce/Consume-Pattern', async () => {
|
|
782
|
-
const client = new Pulsar.Client({
|
|
783
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
784
|
-
operationTimeoutSeconds: 30,
|
|
785
|
-
});
|
|
786
|
-
expect(client).not.toBeNull();
|
|
787
|
-
|
|
788
|
-
const topic1 = 'persistent://public/default/produce-abcdef';
|
|
789
|
-
const topic2 = 'persistent://public/default/produce-abczef';
|
|
790
|
-
const topicsPattern = 'persistent://public/default/produce-abc[a-z]ef';
|
|
791
|
-
const producer1 = await client.createProducer({
|
|
792
|
-
topic: topic1,
|
|
793
|
-
sendTimeoutMs: 30000,
|
|
794
|
-
batchingEnabled: true,
|
|
795
|
-
});
|
|
796
|
-
expect(producer1).not.toBeNull();
|
|
797
|
-
const producer2 = await client.createProducer({
|
|
798
|
-
topic: topic2,
|
|
799
|
-
sendTimeoutMs: 30000,
|
|
800
|
-
batchingEnabled: true,
|
|
801
|
-
});
|
|
802
|
-
expect(producer2).not.toBeNull();
|
|
803
|
-
|
|
804
|
-
const consumer = await client.subscribe({
|
|
805
|
-
topicsPattern,
|
|
806
|
-
subscription: 'sub',
|
|
807
|
-
subscriptionType: 'Shared',
|
|
808
|
-
});
|
|
809
|
-
expect(consumer).not.toBeNull();
|
|
810
|
-
|
|
811
|
-
const messages = [];
|
|
812
|
-
for (let i = 0; i < 5; i += 1) {
|
|
813
|
-
const msg = `my-message-${i}`;
|
|
814
|
-
producer1.send({
|
|
815
|
-
data: Buffer.from(msg),
|
|
816
|
-
});
|
|
817
|
-
messages.push(msg);
|
|
818
|
-
}
|
|
819
|
-
await producer1.flush();
|
|
820
|
-
for (let i = 5; i < 10; i += 1) {
|
|
821
|
-
const msg = `my-message-${i}`;
|
|
822
|
-
producer2.send({
|
|
823
|
-
data: Buffer.from(msg),
|
|
824
|
-
});
|
|
825
|
-
messages.push(msg);
|
|
826
|
-
}
|
|
827
|
-
await producer2.flush();
|
|
828
|
-
|
|
829
|
-
const results = [];
|
|
830
|
-
for (let i = 0; i < 10; i += 1) {
|
|
831
|
-
const msg = await consumer.receive();
|
|
832
|
-
results.push(msg.getData().toString());
|
|
833
|
-
consumer.acknowledge(msg);
|
|
834
|
-
}
|
|
835
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
836
|
-
|
|
837
|
-
await producer1.close();
|
|
838
|
-
await producer2.close();
|
|
839
|
-
await consumer.close();
|
|
840
|
-
await client.close();
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
test('Produce/Consume-Multi-Topic', async () => {
|
|
844
|
-
const client = new Pulsar.Client({
|
|
845
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
846
|
-
operationTimeoutSeconds: 30,
|
|
847
|
-
});
|
|
848
|
-
expect(client).not.toBeNull();
|
|
849
|
-
|
|
850
|
-
const topic1 = 'persistent://public/default/produce-mtopic-1';
|
|
851
|
-
const topic2 = 'persistent://public/default/produce-mtopic-2';
|
|
852
|
-
const producer1 = await client.createProducer({
|
|
853
|
-
topic: topic1,
|
|
854
|
-
sendTimeoutMs: 30000,
|
|
855
|
-
batchingEnabled: true,
|
|
856
|
-
});
|
|
857
|
-
expect(producer1).not.toBeNull();
|
|
858
|
-
const producer2 = await client.createProducer({
|
|
859
|
-
topic: topic2,
|
|
860
|
-
sendTimeoutMs: 30000,
|
|
861
|
-
batchingEnabled: true,
|
|
862
|
-
});
|
|
863
|
-
expect(producer2).not.toBeNull();
|
|
864
|
-
|
|
865
|
-
const consumer = await client.subscribe({
|
|
866
|
-
topics: [topic1, topic2],
|
|
867
|
-
subscription: 'sub',
|
|
868
|
-
subscriptionType: 'Shared',
|
|
869
|
-
});
|
|
870
|
-
expect(consumer).not.toBeNull();
|
|
871
|
-
|
|
872
|
-
const messages = [];
|
|
873
|
-
for (let i = 0; i < 5; i += 1) {
|
|
874
|
-
const msg = `my-message-${i}`;
|
|
875
|
-
producer1.send({
|
|
876
|
-
data: Buffer.from(msg),
|
|
877
|
-
});
|
|
878
|
-
messages.push(msg);
|
|
879
|
-
}
|
|
880
|
-
await producer1.flush();
|
|
881
|
-
for (let i = 5; i < 10; i += 1) {
|
|
882
|
-
const msg = `my-message-${i}`;
|
|
883
|
-
producer2.send({
|
|
884
|
-
data: Buffer.from(msg),
|
|
885
|
-
});
|
|
886
|
-
messages.push(msg);
|
|
887
|
-
}
|
|
888
|
-
await producer2.flush();
|
|
889
|
-
|
|
890
|
-
const results = [];
|
|
891
|
-
for (let i = 0; i < 10; i += 1) {
|
|
892
|
-
const msg = await consumer.receive();
|
|
893
|
-
results.push(msg.getData().toString());
|
|
894
|
-
consumer.acknowledge(msg);
|
|
895
|
-
}
|
|
896
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
897
|
-
|
|
898
|
-
await producer1.close();
|
|
899
|
-
await producer2.close();
|
|
900
|
-
await consumer.close();
|
|
901
|
-
await client.close();
|
|
902
|
-
});
|
|
903
|
-
|
|
904
|
-
test('Produce/Consume and validate MessageId', async () => {
|
|
905
|
-
const client = new Pulsar.Client({
|
|
906
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
907
|
-
operationTimeoutSeconds: 30,
|
|
908
|
-
});
|
|
909
|
-
|
|
910
|
-
const topic = 'persistent://public/default/produce-consume-message-id';
|
|
911
|
-
const producer = await client.createProducer({
|
|
912
|
-
topic,
|
|
913
|
-
sendTimeoutMs: 30000,
|
|
914
|
-
batchingEnabled: true,
|
|
915
|
-
});
|
|
916
|
-
expect(producer).not.toBeNull();
|
|
917
|
-
|
|
918
|
-
const consumer = await client.subscribe({
|
|
919
|
-
topic,
|
|
920
|
-
subscription: 'sub1',
|
|
921
|
-
});
|
|
922
|
-
|
|
923
|
-
expect(consumer).not.toBeNull();
|
|
924
|
-
|
|
925
|
-
const messages = [];
|
|
926
|
-
const messageIds = [];
|
|
927
|
-
for (let i = 0; i < 10; i += 1) {
|
|
928
|
-
const msg = `my-message-${i}`;
|
|
929
|
-
const msgId = await producer.send({
|
|
930
|
-
data: Buffer.from(msg),
|
|
931
|
-
});
|
|
932
|
-
messages.push(msg);
|
|
933
|
-
messageIds.push(msgId.toString());
|
|
934
|
-
}
|
|
935
|
-
|
|
936
|
-
const results = [];
|
|
937
|
-
const resultIds = [];
|
|
938
|
-
for (let i = 0; i < 10; i += 1) {
|
|
939
|
-
const msg = await consumer.receive();
|
|
940
|
-
consumer.acknowledge(msg);
|
|
941
|
-
results.push(msg.getData().toString());
|
|
942
|
-
resultIds.push(msg.getMessageId().toString());
|
|
943
|
-
}
|
|
944
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
945
|
-
expect(lodash.difference(messageIds, resultIds)).toEqual([]);
|
|
946
|
-
await producer.close();
|
|
947
|
-
await consumer.close();
|
|
948
|
-
await client.close();
|
|
949
|
-
});
|
|
950
|
-
test('Basic produce and consume encryption', async () => {
|
|
951
|
-
const client = new Pulsar.Client({
|
|
952
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
953
|
-
operationTimeoutSeconds: 30,
|
|
954
|
-
});
|
|
955
|
-
|
|
956
|
-
const topic = 'persistent://public/default/encryption-produce-consume';
|
|
957
|
-
const producer = await client.createProducer({
|
|
958
|
-
topic,
|
|
959
|
-
sendTimeoutMs: 30000,
|
|
960
|
-
batchingEnabled: true,
|
|
961
|
-
publicKeyPath: `${__dirname}/certificate/public-key.client-rsa.pem`,
|
|
962
|
-
encryptionKey: 'encryption-key',
|
|
963
|
-
});
|
|
964
|
-
|
|
965
|
-
const consumer = await client.subscribe({
|
|
966
|
-
topic,
|
|
967
|
-
subscription: 'sub1',
|
|
968
|
-
subscriptionType: 'Shared',
|
|
969
|
-
ackTimeoutMs: 10000,
|
|
970
|
-
privateKeyPath: `${__dirname}/certificate/private-key.client-rsa.pem`,
|
|
971
|
-
});
|
|
972
|
-
|
|
973
|
-
const messages = [];
|
|
974
|
-
for (let i = 0; i < 10; i += 1) {
|
|
975
|
-
const msg = `my-message-${i}`;
|
|
976
|
-
producer.send({
|
|
977
|
-
data: Buffer.from(msg),
|
|
978
|
-
});
|
|
979
|
-
messages.push(msg);
|
|
980
|
-
}
|
|
981
|
-
await producer.flush();
|
|
982
|
-
|
|
983
|
-
const results = [];
|
|
984
|
-
for (let i = 0; i < 10; i += 1) {
|
|
985
|
-
const msg = await consumer.receive();
|
|
986
|
-
consumer.acknowledge(msg);
|
|
987
|
-
results.push(msg.getData().toString());
|
|
988
|
-
}
|
|
989
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
990
|
-
await producer.close();
|
|
991
|
-
await consumer.close();
|
|
992
|
-
await client.close();
|
|
993
|
-
});
|
|
994
|
-
test('Basic produce and read encryption', async () => {
|
|
995
|
-
const client = new Pulsar.Client({
|
|
996
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
997
|
-
operationTimeoutSeconds: 30,
|
|
998
|
-
});
|
|
999
|
-
|
|
1000
|
-
const topic = 'persistent://public/default/encryption-produce-read';
|
|
1001
|
-
const producer = await client.createProducer({
|
|
1002
|
-
topic,
|
|
1003
|
-
sendTimeoutMs: 30000,
|
|
1004
|
-
batchingEnabled: true,
|
|
1005
|
-
publicKeyPath: `${__dirname}/certificate/public-key.client-rsa.pem`,
|
|
1006
|
-
encryptionKey: 'encryption-key',
|
|
1007
|
-
});
|
|
1008
|
-
|
|
1009
|
-
const reader = await client.createReader({
|
|
1010
|
-
topic,
|
|
1011
|
-
startMessageId: Pulsar.MessageId.earliest(),
|
|
1012
|
-
privateKeyPath: `${__dirname}/certificate/private-key.client-rsa.pem`,
|
|
1013
|
-
});
|
|
1014
|
-
|
|
1015
|
-
const messages = [];
|
|
1016
|
-
for (let i = 0; i < 10; i += 1) {
|
|
1017
|
-
const msg = `my-message-${i}`;
|
|
1018
|
-
producer.send({
|
|
1019
|
-
data: Buffer.from(msg),
|
|
1020
|
-
});
|
|
1021
|
-
messages.push(msg);
|
|
1022
|
-
}
|
|
1023
|
-
await producer.flush();
|
|
1024
|
-
|
|
1025
|
-
const results = [];
|
|
1026
|
-
for (let i = 0; i < 10; i += 1) {
|
|
1027
|
-
const msg = await reader.readNext();
|
|
1028
|
-
results.push(msg.getData().toString());
|
|
1029
|
-
}
|
|
1030
|
-
expect(lodash.difference(messages, results)).toEqual([]);
|
|
1031
|
-
await producer.close();
|
|
1032
|
-
await reader.close();
|
|
1033
|
-
await client.close();
|
|
1034
|
-
});
|
|
1035
|
-
test('Produce/Consume/Read/IsConnected', async () => {
|
|
1036
|
-
const client = new Pulsar.Client({
|
|
1037
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1038
|
-
operationTimeoutSeconds: 30,
|
|
1039
|
-
});
|
|
1040
|
-
|
|
1041
|
-
const topic = 'persistent://public/default/produce-consume';
|
|
1042
|
-
const producer = await client.createProducer({
|
|
1043
|
-
topic,
|
|
1044
|
-
sendTimeoutMs: 30000,
|
|
1045
|
-
batchingEnabled: true,
|
|
1046
|
-
});
|
|
1047
|
-
expect(producer).not.toBeNull();
|
|
1048
|
-
expect(producer.isConnected()).toEqual(true);
|
|
1049
|
-
|
|
1050
|
-
const consumer = await client.subscribe({
|
|
1051
|
-
topic,
|
|
1052
|
-
subscription: 'sub1',
|
|
1053
|
-
ackTimeoutMs: 10000,
|
|
1054
|
-
});
|
|
1055
|
-
expect(consumer).not.toBeNull();
|
|
1056
|
-
expect(consumer.isConnected()).toEqual(true);
|
|
1057
|
-
|
|
1058
|
-
const reader = await client.createReader({
|
|
1059
|
-
topic,
|
|
1060
|
-
startMessageId: Pulsar.MessageId.latest(),
|
|
1061
|
-
});
|
|
1062
|
-
expect(reader).not.toBeNull();
|
|
1063
|
-
expect(reader.isConnected()).toEqual(true);
|
|
1064
|
-
|
|
1065
|
-
await producer.close();
|
|
1066
|
-
expect(producer.isConnected()).toEqual(false);
|
|
1067
|
-
|
|
1068
|
-
await consumer.close();
|
|
1069
|
-
expect(consumer.isConnected()).toEqual(false);
|
|
1070
|
-
|
|
1071
|
-
await reader.close();
|
|
1072
|
-
expect(reader.isConnected()).toEqual(false);
|
|
1073
|
-
|
|
1074
|
-
await client.close();
|
|
1075
|
-
});
|
|
1076
|
-
|
|
1077
|
-
test('Consumer seek by message Id', async () => {
|
|
1078
|
-
const client = new Pulsar.Client({
|
|
1079
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1080
|
-
operationTimeoutSeconds: 30,
|
|
1081
|
-
});
|
|
1082
|
-
|
|
1083
|
-
const topic = 'persistent://public/default/seek-by-msgid';
|
|
1084
|
-
const producer = await client.createProducer({
|
|
1085
|
-
topic,
|
|
1086
|
-
sendTimeoutMs: 30000,
|
|
1087
|
-
batchingEnabled: false,
|
|
1088
|
-
});
|
|
1089
|
-
expect(producer).not.toBeNull();
|
|
1090
|
-
|
|
1091
|
-
const msgIds = [];
|
|
1092
|
-
for (let i = 0; i < 10; i += 1) {
|
|
1093
|
-
const msg = `my-message-${i}`;
|
|
1094
|
-
console.log(msg);
|
|
1095
|
-
const msgId = await producer.send({
|
|
1096
|
-
data: Buffer.from(msg),
|
|
1097
|
-
});
|
|
1098
|
-
msgIds.push(msgId);
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
const consumer = await client.subscribe({
|
|
1102
|
-
topic,
|
|
1103
|
-
subscription: 'sub',
|
|
1104
|
-
});
|
|
1105
|
-
expect(consumer).not.toBeNull();
|
|
1106
|
-
|
|
1107
|
-
await consumer.seek(msgIds[5]);
|
|
1108
|
-
const msg = consumer.receive(1000);
|
|
1109
|
-
console.log((await msg).getMessageId().toString());
|
|
1110
|
-
expect((await msg).getData().toString()).toBe('my-message-6');
|
|
1111
|
-
|
|
1112
|
-
await producer.close();
|
|
1113
|
-
await consumer.close();
|
|
1114
|
-
await client.close();
|
|
1115
|
-
});
|
|
1116
|
-
|
|
1117
|
-
test('Consumer seek by timestamp', async () => {
|
|
1118
|
-
const client = new Pulsar.Client({
|
|
1119
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1120
|
-
operationTimeoutSeconds: 30,
|
|
1121
|
-
});
|
|
1122
|
-
|
|
1123
|
-
const topic = 'persistent://public/default/seek-by-timestamp';
|
|
1124
|
-
const producer = await client.createProducer({
|
|
1125
|
-
topic,
|
|
1126
|
-
sendTimeoutMs: 30000,
|
|
1127
|
-
batchingEnabled: false,
|
|
1128
|
-
});
|
|
1129
|
-
expect(producer).not.toBeNull();
|
|
1130
|
-
|
|
1131
|
-
for (let i = 0; i < 10; i += 1) {
|
|
1132
|
-
const msg = `my-message-${i}`;
|
|
1133
|
-
console.log(msg);
|
|
1134
|
-
await producer.send({
|
|
1135
|
-
data: Buffer.from(msg),
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
|
|
1139
|
-
const consumer = await client.subscribe({
|
|
1140
|
-
topic,
|
|
1141
|
-
subscription: 'sub',
|
|
1142
|
-
});
|
|
1143
|
-
expect(consumer).not.toBeNull();
|
|
1144
|
-
|
|
1145
|
-
const currentTime = Date.now();
|
|
1146
|
-
console.log(currentTime);
|
|
1147
|
-
|
|
1148
|
-
await consumer.seekTimestamp(currentTime);
|
|
1149
|
-
|
|
1150
|
-
console.log('End seek');
|
|
1151
|
-
|
|
1152
|
-
await expect(consumer.receive(1000)).rejects.toThrow('Failed to receive message: TimeOut');
|
|
1153
|
-
|
|
1154
|
-
await consumer.seekTimestamp(currentTime - 100000);
|
|
1155
|
-
|
|
1156
|
-
const msg = consumer.receive(1000);
|
|
1157
|
-
console.log((await msg).getMessageId().toString());
|
|
1158
|
-
expect((await msg).getData().toString()).toBe('my-message-0');
|
|
1159
|
-
|
|
1160
|
-
await producer.close();
|
|
1161
|
-
await consumer.close();
|
|
1162
|
-
await client.close();
|
|
1163
|
-
});
|
|
1164
|
-
|
|
1165
|
-
test('Reader seek by message Id', async () => {
|
|
1166
|
-
const client = new Pulsar.Client({
|
|
1167
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1168
|
-
operationTimeoutSeconds: 30,
|
|
1169
|
-
});
|
|
1170
|
-
|
|
1171
|
-
const topic = 'persistent://public/default/reader-seek-by-msgid';
|
|
1172
|
-
const producer = await client.createProducer({
|
|
1173
|
-
topic,
|
|
1174
|
-
sendTimeoutMs: 30000,
|
|
1175
|
-
batchingEnabled: false,
|
|
1176
|
-
});
|
|
1177
|
-
expect(producer).not.toBeNull();
|
|
1178
|
-
|
|
1179
|
-
const msgIds = [];
|
|
1180
|
-
for (let i = 0; i < 10; i += 1) {
|
|
1181
|
-
const msg = `my-message-${i}`;
|
|
1182
|
-
console.log(msg);
|
|
1183
|
-
const msgId = await producer.send({
|
|
1184
|
-
data: Buffer.from(msg),
|
|
1185
|
-
});
|
|
1186
|
-
msgIds.push(msgId);
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
const reader = await client.createReader({
|
|
1190
|
-
topic,
|
|
1191
|
-
startMessageId: Pulsar.MessageId.latest(),
|
|
1192
|
-
});
|
|
1193
|
-
expect(reader).not.toBeNull();
|
|
1194
|
-
|
|
1195
|
-
await reader.seek(msgIds[5]);
|
|
1196
|
-
expect(reader.hasNext()).toBe(true);
|
|
1197
|
-
const msg = reader.readNext(1000);
|
|
1198
|
-
console.log((await msg).getMessageId().toString());
|
|
1199
|
-
expect((await msg).getData().toString()).toBe('my-message-6');
|
|
1200
|
-
|
|
1201
|
-
await producer.close();
|
|
1202
|
-
await reader.close();
|
|
1203
|
-
await client.close();
|
|
1204
|
-
});
|
|
1205
|
-
|
|
1206
|
-
test('Reader seek by timestamp', async () => {
|
|
1207
|
-
const client = new Pulsar.Client({
|
|
1208
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1209
|
-
operationTimeoutSeconds: 30,
|
|
1210
|
-
});
|
|
1211
|
-
|
|
1212
|
-
const topic = 'persistent://public/default/reader-seek-timestamp';
|
|
1213
|
-
const producer = await client.createProducer({
|
|
1214
|
-
topic,
|
|
1215
|
-
sendTimeoutMs: 30000,
|
|
1216
|
-
batchingEnabled: false,
|
|
1217
|
-
});
|
|
1218
|
-
expect(producer).not.toBeNull();
|
|
1219
|
-
|
|
1220
|
-
for (let i = 0; i < 10; i += 1) {
|
|
1221
|
-
const msg = `my-message-${i}`;
|
|
1222
|
-
console.log(msg);
|
|
1223
|
-
await producer.send({
|
|
1224
|
-
data: Buffer.from(msg),
|
|
1225
|
-
});
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
const reader = await client.createReader({
|
|
1229
|
-
topic,
|
|
1230
|
-
startMessageId: Pulsar.MessageId.latest(),
|
|
1231
|
-
});
|
|
1232
|
-
expect(reader).not.toBeNull();
|
|
1233
|
-
|
|
1234
|
-
const currentTime = Date.now();
|
|
1235
|
-
console.log(currentTime);
|
|
1236
|
-
|
|
1237
|
-
await reader.seekTimestamp(currentTime);
|
|
1238
|
-
|
|
1239
|
-
console.log('End seek');
|
|
1240
|
-
|
|
1241
|
-
expect(reader.hasNext()).toBe(false);
|
|
1242
|
-
|
|
1243
|
-
await reader.seekTimestamp(currentTime - 100000);
|
|
1244
|
-
console.log('Seek to previous time');
|
|
1245
|
-
|
|
1246
|
-
expect(reader.hasNext()).toBe(true);
|
|
1247
|
-
const msg = reader.readNext(1000);
|
|
1248
|
-
console.log((await msg).getMessageId().toString());
|
|
1249
|
-
expect((await msg).getData().toString()).toBe('my-message-0');
|
|
1250
|
-
|
|
1251
|
-
await producer.close();
|
|
1252
|
-
await reader.close();
|
|
1253
|
-
await client.close();
|
|
1254
|
-
});
|
|
1255
|
-
|
|
1256
|
-
test('Message chunking', async () => {
|
|
1257
|
-
const client = new Pulsar.Client({
|
|
1258
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1259
|
-
operationTimeoutSeconds: 30,
|
|
1260
|
-
});
|
|
1261
|
-
|
|
1262
|
-
const topic = 'persistent://public/default/message-chunking';
|
|
1263
|
-
const producer = await client.createProducer({
|
|
1264
|
-
topic,
|
|
1265
|
-
batchingEnabled: false,
|
|
1266
|
-
chunkingEnabled: true,
|
|
1267
|
-
});
|
|
1268
|
-
|
|
1269
|
-
const consumer = await client.subscribe({
|
|
1270
|
-
topic,
|
|
1271
|
-
subscription: 'sub',
|
|
1272
|
-
maxPendingChunkedMessage: 15,
|
|
1273
|
-
autoAckOldestChunkedMessageOnQueueFull: true,
|
|
1274
|
-
});
|
|
1275
|
-
|
|
1276
|
-
const sendMsg = Buffer.alloc(10 * 1024 * 1024);
|
|
1277
|
-
|
|
1278
|
-
await producer.send({
|
|
1279
|
-
data: sendMsg,
|
|
1280
|
-
});
|
|
1281
|
-
|
|
1282
|
-
const receiveMsg = await consumer.receive(3000);
|
|
1283
|
-
expect(receiveMsg.getData().length).toBe(sendMsg.length);
|
|
1284
|
-
await producer.close();
|
|
1285
|
-
await consumer.close();
|
|
1286
|
-
await client.close();
|
|
1287
|
-
});
|
|
1288
|
-
|
|
1289
|
-
test('AuthenticationToken token supplier', async () => {
|
|
1290
|
-
const mockTokenSupplier = jest.fn().mockReturnValue('token');
|
|
1291
|
-
const auth = new Pulsar.AuthenticationToken({
|
|
1292
|
-
token: mockTokenSupplier,
|
|
1293
|
-
});
|
|
1294
|
-
const client = new Pulsar.Client({
|
|
1295
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1296
|
-
authentication: auth,
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
// A producer/consumer is needed to triger the callback function
|
|
1300
|
-
const topic = 'persistent://public/default/token-auth';
|
|
1301
|
-
const producer = await client.createProducer({
|
|
1302
|
-
topic,
|
|
1303
|
-
});
|
|
1304
|
-
expect(producer).not.toBeNull();
|
|
1305
|
-
expect(mockTokenSupplier).toHaveBeenCalledTimes(1);
|
|
1306
|
-
|
|
1307
|
-
await producer.close();
|
|
1308
|
-
await client.close();
|
|
1309
|
-
});
|
|
1310
|
-
|
|
1311
|
-
test('AuthenticationToken async token supplier', async () => {
|
|
1312
|
-
const mockTokenSupplier = jest.fn().mockResolvedValue('token');
|
|
1313
|
-
const auth = new Pulsar.AuthenticationToken({
|
|
1314
|
-
token: mockTokenSupplier,
|
|
1315
|
-
});
|
|
1316
|
-
const client = new Pulsar.Client({
|
|
1317
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1318
|
-
authentication: auth,
|
|
1319
|
-
});
|
|
1320
|
-
|
|
1321
|
-
// A producer/consumer is needed to triger the callback function
|
|
1322
|
-
const topic = 'persistent://public/default/token-auth';
|
|
1323
|
-
const producer = await client.createProducer({
|
|
1324
|
-
topic,
|
|
1325
|
-
});
|
|
1326
|
-
expect(producer).not.toBeNull();
|
|
1327
|
-
expect(mockTokenSupplier).toHaveBeenCalledTimes(1);
|
|
1328
|
-
|
|
1329
|
-
await producer.close();
|
|
1330
|
-
await client.close();
|
|
1331
|
-
});
|
|
1332
|
-
});
|
|
1333
|
-
describe('KeyBasedBatchingTest', () => {
|
|
1334
|
-
let client;
|
|
1335
|
-
let producer;
|
|
1336
|
-
let consumer;
|
|
1337
|
-
let topicName;
|
|
1338
|
-
|
|
1339
|
-
beforeAll(async () => {
|
|
1340
|
-
client = new Pulsar.Client({
|
|
1341
|
-
serviceUrl: 'pulsar://localhost:6650',
|
|
1342
|
-
});
|
|
1343
|
-
});
|
|
1344
|
-
|
|
1345
|
-
afterAll(async () => {
|
|
1346
|
-
await client.close();
|
|
1347
|
-
});
|
|
1348
|
-
|
|
1349
|
-
beforeEach(async () => {
|
|
1350
|
-
topicName = `KeyBasedBatchingTest-${Date.now()}`;
|
|
1351
|
-
});
|
|
1352
|
-
|
|
1353
|
-
afterEach(async () => {
|
|
1354
|
-
if (producer) await producer.close();
|
|
1355
|
-
if (consumer) await consumer.close();
|
|
1356
|
-
});
|
|
1357
|
-
|
|
1358
|
-
const initProducer = async (maxMessages) => {
|
|
1359
|
-
producer = await client.createProducer({
|
|
1360
|
-
topic: topicName,
|
|
1361
|
-
batchingEnabled: true,
|
|
1362
|
-
batchingMaxMessages: maxMessages,
|
|
1363
|
-
batchingType: 'KeyBasedBatching',
|
|
1364
|
-
batchingMaxPublishDelayMs: 3600 * 1000,
|
|
1365
|
-
});
|
|
1366
|
-
};
|
|
1367
|
-
|
|
1368
|
-
const initConsumer = async () => {
|
|
1369
|
-
consumer = await client.subscribe({
|
|
1370
|
-
topic: topicName,
|
|
1371
|
-
subscription: 'SubscriptionName',
|
|
1372
|
-
subscriptionType: 'Exclusive',
|
|
1373
|
-
});
|
|
1374
|
-
};
|
|
1375
|
-
|
|
1376
|
-
const receiveAndAck = async () => {
|
|
1377
|
-
const msg = await consumer.receive();
|
|
1378
|
-
await consumer.acknowledge(msg);
|
|
1379
|
-
return msg;
|
|
1380
|
-
};
|
|
1381
|
-
|
|
1382
|
-
test('testSequenceId', async () => {
|
|
1383
|
-
await initProducer(6);
|
|
1384
|
-
await initConsumer();
|
|
1385
|
-
|
|
1386
|
-
// 0. Send 6 messages, use different keys and order
|
|
1387
|
-
producer.send({ data: Buffer.from('0'), partitionKey: 'A' });
|
|
1388
|
-
producer.send({ data: Buffer.from('1'), partitionKey: 'B' });
|
|
1389
|
-
producer.send({ data: Buffer.from('2'), partitionKey: 'C' });
|
|
1390
|
-
producer.send({ data: Buffer.from('3'), partitionKey: 'B' });
|
|
1391
|
-
producer.send({ data: Buffer.from('4'), partitionKey: 'C' });
|
|
1392
|
-
producer.send({ data: Buffer.from('5'), partitionKey: 'A' });
|
|
1393
|
-
await producer.flush();
|
|
1394
|
-
|
|
1395
|
-
// 1. Receive all messages
|
|
1396
|
-
const received = [];
|
|
1397
|
-
for (let i = 0; i < 6; i += 1) {
|
|
1398
|
-
const msg = await receiveAndAck();
|
|
1399
|
-
received.push({
|
|
1400
|
-
key: msg.getPartitionKey().toString(),
|
|
1401
|
-
value: msg.getData().toString(),
|
|
1402
|
-
});
|
|
1403
|
-
}
|
|
1404
|
-
|
|
1405
|
-
// 2. Verify message order (based on key dictionary order)
|
|
1406
|
-
const expected = [
|
|
1407
|
-
{ key: 'B', value: '1' },
|
|
1408
|
-
{ key: 'B', value: '3' },
|
|
1409
|
-
{ key: 'C', value: '2' },
|
|
1410
|
-
{ key: 'C', value: '4' },
|
|
1411
|
-
{ key: 'A', value: '0' },
|
|
1412
|
-
{ key: 'A', value: '5' },
|
|
1413
|
-
];
|
|
1414
|
-
|
|
1415
|
-
expect(received).toEqual(expected);
|
|
1416
|
-
});
|
|
1417
|
-
|
|
1418
|
-
test('testOrderingKeyPriority', async () => {
|
|
1419
|
-
await initProducer(3);
|
|
1420
|
-
await initConsumer();
|
|
1421
|
-
|
|
1422
|
-
// 1. Send 3 messages to verify orderingKey takes precedence over partitionKey
|
|
1423
|
-
producer.send({
|
|
1424
|
-
data: Buffer.from('0'),
|
|
1425
|
-
orderingKey: 'A',
|
|
1426
|
-
partitionKey: 'B',
|
|
1427
|
-
});
|
|
1428
|
-
producer.send({ data: Buffer.from('2'), orderingKey: 'B' });
|
|
1429
|
-
producer.send({ data: Buffer.from('1'), orderingKey: 'A' });
|
|
1430
|
-
await producer.flush();
|
|
1431
|
-
|
|
1432
|
-
// 2. Receive messages and verify their order and keys
|
|
1433
|
-
const msg1 = await receiveAndAck();
|
|
1434
|
-
expect(msg1.getData().toString()).toBe('2');
|
|
1435
|
-
expect(msg1.getOrderingKey().toString()).toBe('B');
|
|
1436
|
-
|
|
1437
|
-
const msg2 = await receiveAndAck();
|
|
1438
|
-
expect(msg2.getData().toString()).toBe('0');
|
|
1439
|
-
expect(msg2.getOrderingKey()).toBe('A');
|
|
1440
|
-
expect(msg2.getPartitionKey()).toBe('B');
|
|
1441
|
-
|
|
1442
|
-
const msg3 = await receiveAndAck();
|
|
1443
|
-
expect(msg3.getData().toString()).toBe('1');
|
|
1444
|
-
expect(msg3.getOrderingKey().toString()).toBe('A');
|
|
1445
|
-
});
|
|
1446
|
-
});
|
|
1447
|
-
})();
|