pulsar-client 1.6.2 → 1.8.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 (76) hide show
  1. package/.asf.yaml +8 -1
  2. package/.github/PULL_REQUEST_TEMPLATE.md +85 -0
  3. package/.github/workflows/ci-build-release-napi.yml +213 -0
  4. package/.github/workflows/ci-pr-validation.yml +233 -0
  5. package/README.md +91 -68
  6. package/binding.gyp +48 -39
  7. package/{pulsar-test-service-stop.sh → build-support/dep-version.py} +4 -6
  8. package/build-support/download-release-artifacts.py +74 -0
  9. package/build-support/generate-source-archive.sh +28 -0
  10. package/{pulsar-test-service-start.sh → build-support/pulsar-test-container-start.sh} +11 -21
  11. package/build-support/pulsar-test-service-start.sh +37 -0
  12. package/build-support/pulsar-test-service-stop.sh +32 -0
  13. package/{.github/workflows/nodejs.yml → build-support/sign-files.sh} +13 -12
  14. package/build-support/stage-release.sh +44 -0
  15. package/dependencies.yaml +28 -0
  16. package/docs/release-process.md +271 -0
  17. package/examples/consumer.js +1 -1
  18. package/examples/consumer_listener.js +1 -1
  19. package/examples/consumer_tls_auth.js +1 -1
  20. package/examples/custom_logger.js +60 -0
  21. package/examples/encryption-consumer.js +1 -1
  22. package/examples/encryption-producer.js +1 -1
  23. package/examples/producer.js +1 -1
  24. package/examples/producer_tls_auth.js +1 -1
  25. package/examples/reader.js +1 -1
  26. package/examples/reader_listener.js +1 -1
  27. package/index.d.ts +12 -4
  28. package/index.js +2 -1
  29. package/package.json +16 -13
  30. package/pkg/linux/Dockerfile_linux_glibc +35 -0
  31. package/pkg/linux/Dockerfile_linux_musl +32 -0
  32. package/pkg/linux/build-napi-inside-docker.sh +31 -0
  33. package/pkg/linux/download-cpp-client.sh +65 -0
  34. package/pkg/load_test.js +34 -0
  35. package/pkg/mac/build-cpp-deps-lib.sh +186 -0
  36. package/pkg/mac/build-cpp-lib.sh +48 -0
  37. package/{docker-tests.sh → pkg/mac/common.sh} +13 -13
  38. package/pkg/windows/download-cpp-client.bat +12 -0
  39. package/pulsar-client-cpp.txt +2 -0
  40. package/src/AuthenticationAthenz.js +1 -1
  41. package/src/AuthenticationOauth2.js +1 -1
  42. package/src/AuthenticationTls.js +1 -1
  43. package/src/AuthenticationToken.js +1 -1
  44. package/src/Client.cc +84 -58
  45. package/src/Client.h +6 -4
  46. package/src/Consumer.cc +331 -234
  47. package/src/Consumer.h +11 -9
  48. package/src/ConsumerConfig.cc +54 -32
  49. package/src/ConsumerConfig.h +5 -6
  50. package/src/Message.cc +26 -29
  51. package/src/Message.h +4 -4
  52. package/src/MessageId.cc +19 -22
  53. package/src/MessageId.h +5 -6
  54. package/src/MessageListener.h +3 -8
  55. package/src/Producer.cc +116 -133
  56. package/src/Producer.h +3 -3
  57. package/src/ProducerConfig.cc +39 -22
  58. package/src/ProducerConfig.h +2 -2
  59. package/src/Reader.cc +147 -128
  60. package/src/Reader.h +5 -3
  61. package/src/ReaderConfig.cc +14 -20
  62. package/src/ReaderConfig.h +5 -6
  63. package/src/ReaderListener.h +2 -7
  64. package/src/SchemaInfo.cc +78 -0
  65. package/src/SchemaInfo.h +41 -0
  66. package/src/ThreadSafeDeferred.cc +98 -0
  67. package/src/ThreadSafeDeferred.h +85 -0
  68. package/src/pulsar-binding.js +26 -0
  69. package/tests/conf/standalone.conf +6 -0
  70. package/tests/consumer.test.js +2 -2
  71. package/tests/docker-load-test.sh +35 -0
  72. package/tests/end_to_end.test.js +214 -2
  73. package/tests/load-test.sh +43 -0
  74. package/tests/producer.test.js +2 -2
  75. package/{run-unit-tests.sh → tests/run-unit-tests.sh} +6 -15
  76. 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,26 @@
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
+ const path = require('path');
20
+ const binary = require('@mapbox/node-pre-gyp');
21
+
22
+ const bindingPath = binary.find(path.resolve(path.join(__dirname, '../package.json')));
23
+ // eslint-disable-next-line import/no-dynamic-require
24
+ const binding = require(bindingPath);
25
+ // eslint-disable-next-line no-multi-assign
26
+ 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
+
@@ -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: ConnectError');
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: ConnectError');
114
+ })).rejects.toThrow('Failed to create consumer: BrokerMetadataError');
115
115
  });
116
116
 
117
117
  test('Not Positive NAckRedeliverTimeout', async () => {
@@ -0,0 +1,35 @@
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
@@ -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 received message TimeOut',
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 received message TimeOut',
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
  })();
@@ -0,0 +1,43 @@
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
+ # Test if the Pulsar.node built from ../pkg/linux/build-napi-inside-docker.sh
22
+ # can be loaded in other Linux distributions.
23
+
24
+ set -e
25
+
26
+ if [[ $# -lt 2 ]]; then
27
+ echo "Usage $0 <node-image-name> <platform>
28
+
29
+ See https://hub.docker.com/_/node for valid images"
30
+ exit 1
31
+ fi
32
+ IMAGE=$1
33
+ PLATFORM=$2
34
+
35
+ ROOT_DIR=${ROOT_DIR:-$(git rev-parse --show-toplevel)}
36
+ cd $ROOT_DIR
37
+
38
+ git archive -o pulsar-client-node.tar.gz HEAD
39
+
40
+ docker run --platform $PLATFORM -v $PWD:/pulsar-client-node $IMAGE \
41
+ /bin/bash /pulsar-client-node/tests/docker-load-test.sh
42
+
43
+ rm pulsar-client-node.tar.gz
@@ -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: ConnectError');
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: ConnectError');
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
- # install pulsar cpp client pkg
27
- VERSION="${VERSION:-`cat ./pulsar-version.txt`}"
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
26
+ # download pulsar cpp client
27
+ pkg/linux/download-cpp-client.sh
38
28
 
39
- ./pulsar-test-service-start.sh
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
- ./pulsar-test-service-stop.sh
33
+ build-support/pulsar-test-service-stop.sh
43
34
 
44
35
  exit $RES
@@ -1 +0,0 @@
1
- 2.8.0