pulsar-client 1.8.2 → 1.9.0
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/.github/workflows/ci-pr-validation.yml +67 -0
- package/README.md +15 -5
- package/binding.gyp +34 -12
- package/build-support/pulsar-test-service-start.sh +1 -1
- package/docs/release-process.md +11 -0
- package/examples/encryption-reader.js +44 -0
- package/index.d.ts +51 -0
- package/package.json +1 -1
- package/perf/perf_producer.js +2 -2
- package/pulsar-client-cpp.txt +2 -2
- package/src/Client.cc +36 -0
- package/src/Client.h +4 -2
- package/src/Client.js +4 -0
- package/src/Consumer.cc +35 -9
- package/src/Consumer.h +2 -0
- package/src/ConsumerConfig.cc +50 -0
- package/src/LogUtils.h +32 -0
- package/src/ProducerConfig.cc +14 -0
- package/src/Reader.cc +3 -1
- package/src/ReaderConfig.cc +24 -0
- package/tests/client.test.js +69 -0
- package/tests/conf/standalone.conf +3 -0
- package/tests/consumer.test.js +178 -2
- package/tests/end_to_end.test.js +101 -0
- package/tests/http_utils.js +45 -0
- package/tests/producer.test.js +64 -2
- package/tests/reader.test.js +64 -0
- package/tstest.ts +44 -0
package/tests/reader.test.js
CHANGED
|
@@ -17,7 +17,11 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
const lodash = require('lodash');
|
|
20
21
|
const Pulsar = require('../index.js');
|
|
22
|
+
const httpRequest = require('./http_utils');
|
|
23
|
+
|
|
24
|
+
const baseUrl = 'http://localhost:8080';
|
|
21
25
|
|
|
22
26
|
(() => {
|
|
23
27
|
describe('Reader', () => {
|
|
@@ -66,5 +70,65 @@ const Pulsar = require('../index.js');
|
|
|
66
70
|
})).rejects.toThrow('StartMessageId is required and must be specified as a MessageId object when creating reader');
|
|
67
71
|
await client.close();
|
|
68
72
|
});
|
|
73
|
+
|
|
74
|
+
test('Reader by Partitioned Topic', async () => {
|
|
75
|
+
const client = new Pulsar.Client({
|
|
76
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
77
|
+
operationTimeoutSeconds: 30,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Create partitioned topic.
|
|
81
|
+
const partitionedTopicName = 'test-reader-partitioned-topic';
|
|
82
|
+
const partitionedTopic = `persistent://public/default/${partitionedTopicName}`;
|
|
83
|
+
const partitionedTopicAdminURL = `${baseUrl}/admin/v2/persistent/public/default/${partitionedTopicName}/partitions`;
|
|
84
|
+
const createPartitionedTopicRes = await httpRequest(
|
|
85
|
+
partitionedTopicAdminURL, {
|
|
86
|
+
headers: {
|
|
87
|
+
'Content-Type': 'text/plain',
|
|
88
|
+
},
|
|
89
|
+
data: 4,
|
|
90
|
+
method: 'PUT',
|
|
91
|
+
},
|
|
92
|
+
);
|
|
93
|
+
expect(createPartitionedTopicRes.statusCode).toBe(204);
|
|
94
|
+
|
|
95
|
+
const producer = await client.createProducer({
|
|
96
|
+
topic: partitionedTopic,
|
|
97
|
+
sendTimeoutMs: 30000,
|
|
98
|
+
batchingEnabled: true,
|
|
99
|
+
});
|
|
100
|
+
expect(producer).not.toBeNull();
|
|
101
|
+
|
|
102
|
+
const reader = await client.createReader({
|
|
103
|
+
topic: partitionedTopic,
|
|
104
|
+
startMessageId: Pulsar.MessageId.latest(),
|
|
105
|
+
});
|
|
106
|
+
expect(reader).not.toBeNull();
|
|
107
|
+
|
|
108
|
+
const messages = [];
|
|
109
|
+
for (let i = 0; i < 10; i += 1) {
|
|
110
|
+
const msg = `my-message-${i}`;
|
|
111
|
+
producer.send({
|
|
112
|
+
data: Buffer.from(msg),
|
|
113
|
+
});
|
|
114
|
+
messages.push(msg);
|
|
115
|
+
}
|
|
116
|
+
await producer.flush();
|
|
117
|
+
|
|
118
|
+
expect(reader.hasNext()).toBe(true);
|
|
119
|
+
|
|
120
|
+
const results = [];
|
|
121
|
+
for (let i = 0; i < 10; i += 1) {
|
|
122
|
+
const msg = await reader.readNext();
|
|
123
|
+
results.push(msg.getData().toString());
|
|
124
|
+
}
|
|
125
|
+
expect(lodash.difference(messages, results)).toEqual([]);
|
|
126
|
+
|
|
127
|
+
expect(reader.hasNext()).toBe(false);
|
|
128
|
+
|
|
129
|
+
await producer.close();
|
|
130
|
+
await reader.close();
|
|
131
|
+
await client.close();
|
|
132
|
+
});
|
|
69
133
|
});
|
|
70
134
|
})();
|
package/tstest.ts
CHANGED
|
@@ -133,6 +133,19 @@ import Pulsar = require('./index');
|
|
|
133
133
|
compressionType: 'SNAPPY',
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
+
const producer5: Pulsar.Producer = await client.createProducer({
|
|
137
|
+
topic: 'persistent://public/default/my-topic',
|
|
138
|
+
schema: {
|
|
139
|
+
name: 'my-schema',
|
|
140
|
+
schemaType: "Json",
|
|
141
|
+
schema: "my-json-schema",
|
|
142
|
+
properties: {
|
|
143
|
+
key1: 'value1',
|
|
144
|
+
key2: 'value2'
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
136
149
|
const consumer1: Pulsar.Consumer = await client.subscribe({
|
|
137
150
|
topic: 'persistent://public/default/my-topic',
|
|
138
151
|
subscription: 'my-sub1',
|
|
@@ -175,6 +188,20 @@ import Pulsar = require('./index');
|
|
|
175
188
|
subscriptionType: 'Failover',
|
|
176
189
|
});
|
|
177
190
|
|
|
191
|
+
const consumer5: Pulsar.Consumer = await client.subscribe({
|
|
192
|
+
topic: 'persistent://public/default/my-topic',
|
|
193
|
+
subscription: 'my-sub5',
|
|
194
|
+
schema: {
|
|
195
|
+
name: 'my-schema',
|
|
196
|
+
schemaType: "Json",
|
|
197
|
+
schema: "my-json-schema",
|
|
198
|
+
properties: {
|
|
199
|
+
key1: 'value1',
|
|
200
|
+
key2: 'value2'
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
|
|
178
205
|
const reader1: Pulsar.Reader = await client.createReader({
|
|
179
206
|
topic: 'persistent://public/default/my-topic',
|
|
180
207
|
startMessageId: Pulsar.MessageId.latest(),
|
|
@@ -196,6 +223,19 @@ import Pulsar = require('./index');
|
|
|
196
223
|
},
|
|
197
224
|
});
|
|
198
225
|
|
|
226
|
+
const reader4: Pulsar.Reader = await client.createReader({
|
|
227
|
+
topic: 'persistent://public/default/my-topic',
|
|
228
|
+
startMessageId: Pulsar.MessageId.earliest(),
|
|
229
|
+
privateKeyPath: '/path/to/private.key',
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const reader5: Pulsar.Reader = await client.createReader({
|
|
233
|
+
topic: 'persistent://public/default/my-topic',
|
|
234
|
+
startMessageId: Pulsar.MessageId.earliest(),
|
|
235
|
+
privateKeyPath: '/path/to/private.key',
|
|
236
|
+
cryptoFailureAction: 'CONSUME',
|
|
237
|
+
});
|
|
238
|
+
|
|
199
239
|
const producerName: string = producer1.getProducerName();
|
|
200
240
|
const topicName1: string = producer1.getTopic();
|
|
201
241
|
const producerIsConnected: boolean = producer1.isConnected();
|
|
@@ -253,13 +293,17 @@ import Pulsar = require('./index');
|
|
|
253
293
|
await producer2.close();
|
|
254
294
|
await producer3.close();
|
|
255
295
|
await producer4.close();
|
|
296
|
+
await producer5.close();
|
|
256
297
|
await consumer1.unsubscribe();
|
|
257
298
|
await consumer2.close();
|
|
258
299
|
await consumer3.close();
|
|
259
300
|
await consumer4.close();
|
|
301
|
+
await consumer5.close();
|
|
260
302
|
await reader1.close();
|
|
261
303
|
await reader2.close();
|
|
262
304
|
await reader3.close();
|
|
305
|
+
await reader4.close();
|
|
306
|
+
await reader5.close();
|
|
263
307
|
await client.close();
|
|
264
308
|
})();
|
|
265
309
|
|