pulsar-client 1.6.2 → 1.8.0-rc1
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/.asf.yaml +8 -1
- package/.github/PULL_REQUEST_TEMPLATE.md +65 -0
- package/.github/workflows/ci-build-release-napi.yml +195 -0
- package/.github/workflows/ci-pr-validation.yml +225 -0
- package/README.md +87 -68
- package/binding.gyp +41 -39
- package/{pulsar-test-service-stop.sh → build-support/dep-version.py} +4 -6
- package/build-support/download-release-artifacts.py +74 -0
- package/build-support/generate-source-archive.sh +28 -0
- package/build-support/install-cpp-client.sh +66 -0
- package/{pulsar-test-service-start.sh → build-support/pulsar-test-container-start.sh} +11 -21
- package/build-support/pulsar-test-service-start.sh +37 -0
- package/build-support/pulsar-test-service-stop.sh +32 -0
- package/{.github/workflows/nodejs.yml → build-support/sign-files.sh} +13 -12
- package/build-support/stage-release.sh +44 -0
- package/dependencies.yaml +28 -0
- package/docs/release-process.md +242 -0
- package/examples/consumer.js +1 -1
- package/examples/consumer_listener.js +1 -1
- package/examples/consumer_tls_auth.js +1 -1
- package/examples/custom_logger.js +60 -0
- package/examples/encryption-consumer.js +1 -1
- package/examples/encryption-producer.js +1 -1
- package/examples/producer.js +1 -1
- package/examples/producer_tls_auth.js +1 -1
- package/examples/reader.js +1 -1
- package/examples/reader_listener.js +1 -1
- package/index.d.ts +12 -4
- package/index.js +2 -1
- package/package.json +14 -12
- package/pkg/build-napi-inside-docker.sh +31 -0
- package/pkg/linux_glibc/Dockerfile +33 -0
- package/pkg/linux_musl/Dockerfile +32 -0
- package/pkg/load_test.js +30 -0
- package/pkg/mac/build-cpp-deps-lib.sh +186 -0
- package/pkg/mac/build-cpp-lib.sh +51 -0
- package/{docker-tests.sh → pkg/mac/common.sh} +13 -13
- package/pkg/windows/download-cpp-client.bat +12 -0
- package/pulsar-client-cpp.txt +2 -0
- package/src/AuthenticationAthenz.js +1 -1
- package/src/AuthenticationOauth2.js +1 -1
- package/src/AuthenticationTls.js +1 -1
- package/src/AuthenticationToken.js +1 -1
- package/src/Client.cc +84 -58
- package/src/Client.h +6 -4
- package/src/Consumer.cc +331 -234
- package/src/Consumer.h +11 -9
- package/src/ConsumerConfig.cc +54 -32
- package/src/ConsumerConfig.h +5 -6
- package/src/Message.cc +26 -29
- package/src/Message.h +4 -4
- package/src/MessageId.cc +19 -22
- package/src/MessageId.h +5 -6
- package/src/MessageListener.h +3 -8
- package/src/Producer.cc +116 -133
- package/src/Producer.h +3 -3
- package/src/ProducerConfig.cc +39 -22
- package/src/ProducerConfig.h +2 -2
- package/src/Reader.cc +147 -128
- package/src/Reader.h +5 -3
- package/src/ReaderConfig.cc +14 -20
- package/src/ReaderConfig.h +5 -6
- package/src/ReaderListener.h +2 -7
- package/src/SchemaInfo.cc +78 -0
- package/src/SchemaInfo.h +41 -0
- package/src/ThreadSafeDeferred.cc +98 -0
- package/src/ThreadSafeDeferred.h +85 -0
- package/src/pulsar-binding.js +8 -0
- package/tests/conf/standalone.conf +6 -0
- package/tests/consumer.test.js +2 -2
- package/tests/end_to_end.test.js +214 -2
- package/tests/producer.test.js +2 -2
- package/{run-unit-tests.sh → tests/run-unit-tests.sh} +5 -14
- package/pulsar-version.txt +0 -1
|
@@ -0,0 +1,98 @@
|
|
|
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
|
+
/**
|
|
21
|
+
* MIT License
|
|
22
|
+
*
|
|
23
|
+
* Copyright (c) 2020 Michael K
|
|
24
|
+
*
|
|
25
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
26
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
27
|
+
* in the Software without restriction, including without limitation the rights
|
|
28
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
29
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
30
|
+
* furnished to do so, subject to the following conditions:
|
|
31
|
+
*
|
|
32
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
33
|
+
* copies or substantial portions of the Software.
|
|
34
|
+
*
|
|
35
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
36
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
37
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
38
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
39
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
41
|
+
* SOFTWARE.
|
|
42
|
+
*
|
|
43
|
+
*
|
|
44
|
+
* Adapted from https://github.com/0815fox/node-napi-threadsafe-deferred/tree/master/src
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
#include "ThreadSafeDeferred.h"
|
|
48
|
+
|
|
49
|
+
std::shared_ptr<ThreadSafeDeferred> ThreadSafeDeferred::New(const Napi::Env env) {
|
|
50
|
+
auto deferred = std::make_shared<ThreadSafeDeferred>(env);
|
|
51
|
+
deferred->self = deferred;
|
|
52
|
+
return deferred;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
ThreadSafeDeferred::ThreadSafeDeferred(const Napi::Env env)
|
|
56
|
+
: Deferred(env),
|
|
57
|
+
fate(EFate::UNRESOLVED),
|
|
58
|
+
createValueCb(NULL),
|
|
59
|
+
errorMsg(""),
|
|
60
|
+
tsf{Napi::ThreadSafeFunction::New(env, Napi::Function::New(env, [](const Napi::CallbackInfo &info) {}),
|
|
61
|
+
"ThreadSafeDeferred", 0, 1, [this](Napi::Env env) {
|
|
62
|
+
// this access happens from another thread.
|
|
63
|
+
// However, no synchronization is needed as
|
|
64
|
+
// the other thread cannot modify this instance
|
|
65
|
+
// anymore after calling Resolve or Reject.
|
|
66
|
+
if (this->fate == EFate::RESOLVED) {
|
|
67
|
+
if (this->createValueCb == NULL) {
|
|
68
|
+
Napi::Promise::Deferred::Resolve(env.Undefined());
|
|
69
|
+
} else {
|
|
70
|
+
Napi::Promise::Deferred::Resolve(this->createValueCb(env));
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
Napi::Promise::Deferred::Reject(
|
|
74
|
+
Napi::Error::New(env, this->errorMsg).Value());
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
this->self.reset();
|
|
78
|
+
})} {}
|
|
79
|
+
|
|
80
|
+
void ThreadSafeDeferred::Resolve() {
|
|
81
|
+
if (this->fate != EFate::UNRESOLVED) throw "Cannot resolve a promise which is not unresolved anymore.";
|
|
82
|
+
this->fate = EFate::RESOLVED;
|
|
83
|
+
this->tsf.Release();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void ThreadSafeDeferred::Resolve(const createValueCb_t createValueCb) {
|
|
87
|
+
if (this->fate != EFate::UNRESOLVED) throw "Cannot resolve a promise which is not unresolved anymore.";
|
|
88
|
+
this->createValueCb = createValueCb;
|
|
89
|
+
this->fate = EFate::RESOLVED;
|
|
90
|
+
this->tsf.Release();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
void ThreadSafeDeferred::Reject(const std::string &errorMsg) {
|
|
94
|
+
if (this->fate != EFate::UNRESOLVED) throw "Cannot reject a promise which is not unresolved anymore.";
|
|
95
|
+
this->errorMsg = errorMsg;
|
|
96
|
+
this->fate = EFate::REJECTED;
|
|
97
|
+
this->tsf.Release();
|
|
98
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
/**
|
|
21
|
+
* MIT License
|
|
22
|
+
*
|
|
23
|
+
* Copyright (c) 2020 Michael K
|
|
24
|
+
*
|
|
25
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
26
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
27
|
+
* in the Software without restriction, including without limitation the rights
|
|
28
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
29
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
30
|
+
* furnished to do so, subject to the following conditions:
|
|
31
|
+
*
|
|
32
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
33
|
+
* copies or substantial portions of the Software.
|
|
34
|
+
*
|
|
35
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
36
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
37
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
38
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
39
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
40
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
41
|
+
* SOFTWARE.
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
#ifndef __THREADSAFE_DEFERRED_HPP
|
|
45
|
+
#define __THREADSAFE_DEFERRED_HPP
|
|
46
|
+
|
|
47
|
+
#include <napi.h>
|
|
48
|
+
#include <functional>
|
|
49
|
+
|
|
50
|
+
#define THREADSAFE_DEFERRED_RESOLVER(result) [=](const Napi::Env env) { return result; }
|
|
51
|
+
|
|
52
|
+
typedef std::function<Napi::Value(const Napi::Env env)> createValueCb_t;
|
|
53
|
+
|
|
54
|
+
class ThreadSafeDeferred : public Napi::Promise::Deferred {
|
|
55
|
+
private:
|
|
56
|
+
enum class EFate
|
|
57
|
+
{
|
|
58
|
+
UNRESOLVED,
|
|
59
|
+
RESOLVED,
|
|
60
|
+
REJECTED
|
|
61
|
+
};
|
|
62
|
+
EFate fate;
|
|
63
|
+
createValueCb_t createValueCb;
|
|
64
|
+
std::string errorMsg;
|
|
65
|
+
Napi::ThreadSafeFunction tsf;
|
|
66
|
+
std::shared_ptr<ThreadSafeDeferred> self;
|
|
67
|
+
|
|
68
|
+
public:
|
|
69
|
+
ThreadSafeDeferred(const Napi::Env env);
|
|
70
|
+
|
|
71
|
+
void Resolve(); // <- if only Resolve were virtual... But we can live without polymorphism here
|
|
72
|
+
void Resolve(const createValueCb_t);
|
|
73
|
+
inline void Reject() { this->Reject(""); }
|
|
74
|
+
void Reject(
|
|
75
|
+
const std::string &); // <- if only Reject were virtual... But we can live without polymorphism here
|
|
76
|
+
|
|
77
|
+
static std::shared_ptr<ThreadSafeDeferred> New(const Napi::Env env);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
struct ExtDeferredContext {
|
|
81
|
+
ExtDeferredContext(std::shared_ptr<ThreadSafeDeferred> deferred) : deferred(deferred){};
|
|
82
|
+
std::shared_ptr<ThreadSafeDeferred> deferred;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
#endif /* __THREADSAFE_DEFERRED_HPP */
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const binary = require('@mapbox/node-pre-gyp');
|
|
3
|
+
|
|
4
|
+
const bindingPath = binary.find(path.resolve(path.join(__dirname, '../package.json')));
|
|
5
|
+
// eslint-disable-next-line import/no-dynamic-require
|
|
6
|
+
const binding = require(bindingPath);
|
|
7
|
+
// eslint-disable-next-line no-multi-assign
|
|
8
|
+
module.exports = exports = binding;
|
|
@@ -275,3 +275,9 @@ keepAliveIntervalSeconds=30
|
|
|
275
275
|
|
|
276
276
|
# How often broker checks for inactive topics to be deleted (topics with no subscriptions and no one connected)
|
|
277
277
|
brokerServicePurgeInactiveFrequencyInSeconds=60
|
|
278
|
+
|
|
279
|
+
### --- BookKeeper Configuration --- #####
|
|
280
|
+
|
|
281
|
+
# The maximum netty frame size in bytes. Any message received larger than this will be rejected. The default value is 5MB.
|
|
282
|
+
nettyMaxFrameSizeBytes=5253120
|
|
283
|
+
|
package/tests/consumer.test.js
CHANGED
|
@@ -102,7 +102,7 @@ const Pulsar = require('../index.js');
|
|
|
102
102
|
subscription: 'sub1',
|
|
103
103
|
ackTimeoutMs: 10000,
|
|
104
104
|
nAckRedeliverTimeoutMs: 60000,
|
|
105
|
-
})).rejects.toThrow('Failed to create consumer:
|
|
105
|
+
})).rejects.toThrow('Failed to create consumer: BrokerMetadataError');
|
|
106
106
|
});
|
|
107
107
|
|
|
108
108
|
test('Not Exist Namespace', async () => {
|
|
@@ -111,7 +111,7 @@ const Pulsar = require('../index.js');
|
|
|
111
111
|
subscription: 'sub1',
|
|
112
112
|
ackTimeoutMs: 10000,
|
|
113
113
|
nAckRedeliverTimeoutMs: 60000,
|
|
114
|
-
})).rejects.toThrow('Failed to create consumer:
|
|
114
|
+
})).rejects.toThrow('Failed to create consumer: BrokerMetadataError');
|
|
115
115
|
});
|
|
116
116
|
|
|
117
117
|
test('Not Positive NAckRedeliverTimeout', async () => {
|
package/tests/end_to_end.test.js
CHANGED
|
@@ -106,7 +106,7 @@ const Pulsar = require('../index.js');
|
|
|
106
106
|
consumer.acknowledge(msg2);
|
|
107
107
|
|
|
108
108
|
await expect(consumer.receive(1000)).rejects.toThrow(
|
|
109
|
-
'Failed to
|
|
109
|
+
'Failed to receive message: TimeOut',
|
|
110
110
|
);
|
|
111
111
|
|
|
112
112
|
expect(results).toEqual([message, message]);
|
|
@@ -302,7 +302,7 @@ const Pulsar = require('../index.js');
|
|
|
302
302
|
}
|
|
303
303
|
|
|
304
304
|
await expect(consumer.receive(1000)).rejects.toThrow(
|
|
305
|
-
'Failed to
|
|
305
|
+
'Failed to receive message: TimeOut',
|
|
306
306
|
);
|
|
307
307
|
|
|
308
308
|
await producer.close();
|
|
@@ -847,5 +847,217 @@ const Pulsar = require('../index.js');
|
|
|
847
847
|
|
|
848
848
|
await client.close();
|
|
849
849
|
});
|
|
850
|
+
|
|
851
|
+
test('Consumer seek by message Id', async () => {
|
|
852
|
+
const client = new Pulsar.Client({
|
|
853
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
854
|
+
operationTimeoutSeconds: 30,
|
|
855
|
+
});
|
|
856
|
+
|
|
857
|
+
const topic = 'persistent://public/default/seek-by-msgid';
|
|
858
|
+
const producer = await client.createProducer({
|
|
859
|
+
topic,
|
|
860
|
+
sendTimeoutMs: 30000,
|
|
861
|
+
batchingEnabled: false,
|
|
862
|
+
});
|
|
863
|
+
expect(producer).not.toBeNull();
|
|
864
|
+
|
|
865
|
+
const msgIds = [];
|
|
866
|
+
for (let i = 0; i < 10; i += 1) {
|
|
867
|
+
const msg = `my-message-${i}`;
|
|
868
|
+
console.log(msg);
|
|
869
|
+
const msgId = await producer.send({
|
|
870
|
+
data: Buffer.from(msg),
|
|
871
|
+
});
|
|
872
|
+
msgIds.push(msgId);
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const consumer = await client.subscribe({
|
|
876
|
+
topic,
|
|
877
|
+
subscription: 'sub',
|
|
878
|
+
});
|
|
879
|
+
expect(consumer).not.toBeNull();
|
|
880
|
+
|
|
881
|
+
await consumer.seek(msgIds[5]);
|
|
882
|
+
const msg = consumer.receive(1000);
|
|
883
|
+
console.log((await msg).getMessageId().toString());
|
|
884
|
+
expect((await msg).getData().toString()).toBe('my-message-6');
|
|
885
|
+
|
|
886
|
+
await producer.close();
|
|
887
|
+
await consumer.close();
|
|
888
|
+
await client.close();
|
|
889
|
+
});
|
|
890
|
+
|
|
891
|
+
test('Consumer seek by timestamp', async () => {
|
|
892
|
+
const client = new Pulsar.Client({
|
|
893
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
894
|
+
operationTimeoutSeconds: 30,
|
|
895
|
+
});
|
|
896
|
+
|
|
897
|
+
const topic = 'persistent://public/default/seek-by-timestamp';
|
|
898
|
+
const producer = await client.createProducer({
|
|
899
|
+
topic,
|
|
900
|
+
sendTimeoutMs: 30000,
|
|
901
|
+
batchingEnabled: false,
|
|
902
|
+
});
|
|
903
|
+
expect(producer).not.toBeNull();
|
|
904
|
+
|
|
905
|
+
for (let i = 0; i < 10; i += 1) {
|
|
906
|
+
const msg = `my-message-${i}`;
|
|
907
|
+
console.log(msg);
|
|
908
|
+
await producer.send({
|
|
909
|
+
data: Buffer.from(msg),
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
const consumer = await client.subscribe({
|
|
914
|
+
topic,
|
|
915
|
+
subscription: 'sub',
|
|
916
|
+
});
|
|
917
|
+
expect(consumer).not.toBeNull();
|
|
918
|
+
|
|
919
|
+
const currentTime = Date.now();
|
|
920
|
+
console.log(currentTime);
|
|
921
|
+
|
|
922
|
+
await consumer.seekTimestamp(currentTime);
|
|
923
|
+
|
|
924
|
+
console.log('End seek');
|
|
925
|
+
|
|
926
|
+
await expect(consumer.receive(1000)).rejects.toThrow('Failed to receive message: TimeOut');
|
|
927
|
+
|
|
928
|
+
await consumer.seekTimestamp(currentTime - 100000);
|
|
929
|
+
|
|
930
|
+
const msg = consumer.receive(1000);
|
|
931
|
+
console.log((await msg).getMessageId().toString());
|
|
932
|
+
expect((await msg).getData().toString()).toBe('my-message-0');
|
|
933
|
+
|
|
934
|
+
await producer.close();
|
|
935
|
+
await consumer.close();
|
|
936
|
+
await client.close();
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
test('Reader seek by message Id', async () => {
|
|
940
|
+
const client = new Pulsar.Client({
|
|
941
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
942
|
+
operationTimeoutSeconds: 30,
|
|
943
|
+
});
|
|
944
|
+
|
|
945
|
+
const topic = 'persistent://public/default/reader-seek-by-msgid';
|
|
946
|
+
const producer = await client.createProducer({
|
|
947
|
+
topic,
|
|
948
|
+
sendTimeoutMs: 30000,
|
|
949
|
+
batchingEnabled: false,
|
|
950
|
+
});
|
|
951
|
+
expect(producer).not.toBeNull();
|
|
952
|
+
|
|
953
|
+
const msgIds = [];
|
|
954
|
+
for (let i = 0; i < 10; i += 1) {
|
|
955
|
+
const msg = `my-message-${i}`;
|
|
956
|
+
console.log(msg);
|
|
957
|
+
const msgId = await producer.send({
|
|
958
|
+
data: Buffer.from(msg),
|
|
959
|
+
});
|
|
960
|
+
msgIds.push(msgId);
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
const reader = await client.createReader({
|
|
964
|
+
topic,
|
|
965
|
+
startMessageId: Pulsar.MessageId.latest(),
|
|
966
|
+
});
|
|
967
|
+
expect(reader).not.toBeNull();
|
|
968
|
+
|
|
969
|
+
await reader.seek(msgIds[5]);
|
|
970
|
+
expect(reader.hasNext()).toBe(true);
|
|
971
|
+
const msg = reader.readNext(1000);
|
|
972
|
+
console.log((await msg).getMessageId().toString());
|
|
973
|
+
expect((await msg).getData().toString()).toBe('my-message-6');
|
|
974
|
+
|
|
975
|
+
await producer.close();
|
|
976
|
+
await reader.close();
|
|
977
|
+
await client.close();
|
|
978
|
+
});
|
|
979
|
+
|
|
980
|
+
test('Reader seek by timestamp', async () => {
|
|
981
|
+
const client = new Pulsar.Client({
|
|
982
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
983
|
+
operationTimeoutSeconds: 30,
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
const topic = 'persistent://public/default/reader-seek-timestamp';
|
|
987
|
+
const producer = await client.createProducer({
|
|
988
|
+
topic,
|
|
989
|
+
sendTimeoutMs: 30000,
|
|
990
|
+
batchingEnabled: false,
|
|
991
|
+
});
|
|
992
|
+
expect(producer).not.toBeNull();
|
|
993
|
+
|
|
994
|
+
for (let i = 0; i < 10; i += 1) {
|
|
995
|
+
const msg = `my-message-${i}`;
|
|
996
|
+
console.log(msg);
|
|
997
|
+
await producer.send({
|
|
998
|
+
data: Buffer.from(msg),
|
|
999
|
+
});
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
const reader = await client.createReader({
|
|
1003
|
+
topic,
|
|
1004
|
+
startMessageId: Pulsar.MessageId.latest(),
|
|
1005
|
+
});
|
|
1006
|
+
expect(reader).not.toBeNull();
|
|
1007
|
+
|
|
1008
|
+
const currentTime = Date.now();
|
|
1009
|
+
console.log(currentTime);
|
|
1010
|
+
|
|
1011
|
+
await reader.seekTimestamp(currentTime);
|
|
1012
|
+
|
|
1013
|
+
console.log('End seek');
|
|
1014
|
+
|
|
1015
|
+
expect(reader.hasNext()).toBe(false);
|
|
1016
|
+
|
|
1017
|
+
await reader.seekTimestamp(currentTime - 100000);
|
|
1018
|
+
console.log('Seek to previous time');
|
|
1019
|
+
|
|
1020
|
+
expect(reader.hasNext()).toBe(true);
|
|
1021
|
+
const msg = reader.readNext(1000);
|
|
1022
|
+
console.log((await msg).getMessageId().toString());
|
|
1023
|
+
expect((await msg).getData().toString()).toBe('my-message-0');
|
|
1024
|
+
|
|
1025
|
+
await producer.close();
|
|
1026
|
+
await reader.close();
|
|
1027
|
+
await client.close();
|
|
1028
|
+
});
|
|
1029
|
+
|
|
1030
|
+
test('Message chunking', async () => {
|
|
1031
|
+
const client = new Pulsar.Client({
|
|
1032
|
+
serviceUrl: 'pulsar://localhost:6650',
|
|
1033
|
+
operationTimeoutSeconds: 30,
|
|
1034
|
+
});
|
|
1035
|
+
|
|
1036
|
+
const topic = 'persistent://public/default/message-chunking';
|
|
1037
|
+
const producer = await client.createProducer({
|
|
1038
|
+
topic,
|
|
1039
|
+
batchingEnabled: false,
|
|
1040
|
+
chunkingEnabled: true,
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
const consumer = await client.subscribe({
|
|
1044
|
+
topic,
|
|
1045
|
+
subscription: 'sub',
|
|
1046
|
+
maxPendingChunkedMessage: 15,
|
|
1047
|
+
autoAckOldestChunkedMessageOnQueueFull: true,
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
const sendMsg = Buffer.alloc(10 * 1024 * 1024);
|
|
1051
|
+
|
|
1052
|
+
await producer.send({
|
|
1053
|
+
data: sendMsg,
|
|
1054
|
+
});
|
|
1055
|
+
|
|
1056
|
+
const receiveMsg = await consumer.receive(3000);
|
|
1057
|
+
expect(receiveMsg.getData().length).toBe(sendMsg.length);
|
|
1058
|
+
await producer.close();
|
|
1059
|
+
await consumer.close();
|
|
1060
|
+
await client.close();
|
|
1061
|
+
});
|
|
850
1062
|
});
|
|
851
1063
|
})();
|
package/tests/producer.test.js
CHANGED
|
@@ -55,7 +55,7 @@ const Pulsar = require('../index.js');
|
|
|
55
55
|
topic: 'persistent://no-tenant/namespace/topic',
|
|
56
56
|
sendTimeoutMs: 30000,
|
|
57
57
|
batchingEnabled: true,
|
|
58
|
-
})).rejects.toThrow('Failed to create producer:
|
|
58
|
+
})).rejects.toThrow('Failed to create producer: BrokerMetadataError');
|
|
59
59
|
});
|
|
60
60
|
|
|
61
61
|
test('Not Exist Namespace', async () => {
|
|
@@ -63,7 +63,7 @@ const Pulsar = require('../index.js');
|
|
|
63
63
|
topic: 'persistent://public/no-namespace/topic',
|
|
64
64
|
sendTimeoutMs: 30000,
|
|
65
65
|
batchingEnabled: true,
|
|
66
|
-
})).rejects.toThrow('Failed to create producer:
|
|
66
|
+
})).rejects.toThrow('Failed to create producer: BrokerMetadataError');
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
test('Automatic Producer Name', async () => {
|
|
@@ -20,25 +20,16 @@
|
|
|
20
20
|
|
|
21
21
|
set -e
|
|
22
22
|
|
|
23
|
-
ROOT_DIR=$(git rev-parse --show-toplevel)
|
|
23
|
+
ROOT_DIR=${ROOT_DIR:-$(git rev-parse --show-toplevel)}
|
|
24
24
|
cd $ROOT_DIR
|
|
25
25
|
|
|
26
26
|
# install pulsar cpp client pkg
|
|
27
|
-
|
|
28
|
-
PULSAR_PKG_DIR="/tmp/pulsar-test-pkg"
|
|
29
|
-
rm -rf $PULSAR_PKG_DIR
|
|
30
|
-
for pkg in apache-pulsar-client-dev.deb apache-pulsar-client.deb;do
|
|
31
|
-
curl -L --create-dir "https://archive.apache.org/dist/pulsar/pulsar-${VERSION}/DEB/${pkg}" -o $PULSAR_PKG_DIR/$pkg
|
|
32
|
-
done;
|
|
33
|
-
apt-get -y update
|
|
34
|
-
apt-get install -y software-properties-common
|
|
35
|
-
add-apt-repository ppa:ubuntu-toolchain-r/test && apt-get -y update
|
|
36
|
-
apt-get -y install gcc-4.9 && apt-get upgrade -y libstdc++6
|
|
37
|
-
apt install $PULSAR_PKG_DIR/apache-pulsar-client*.deb
|
|
27
|
+
build-support/install-cpp-client.sh
|
|
38
28
|
|
|
39
|
-
|
|
29
|
+
cd $ROOT_DIR
|
|
30
|
+
build-support/pulsar-test-service-start.sh
|
|
40
31
|
npm install && npm run lint && npm run dtslint && npm run build && npm run test
|
|
41
32
|
RES=$?
|
|
42
|
-
|
|
33
|
+
build-support/pulsar-test-service-stop.sh
|
|
43
34
|
|
|
44
35
|
exit $RES
|
package/pulsar-version.txt
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.8.0
|