pulsar-client 1.7.0 → 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.
Files changed (55) hide show
  1. package/.asf.yaml +8 -1
  2. package/.github/PULL_REQUEST_TEMPLATE.md +65 -0
  3. package/.github/workflows/ci-build-release-napi.yml +195 -0
  4. package/.github/workflows/ci-pr-validation.yml +225 -0
  5. package/README.md +83 -107
  6. package/binding.gyp +28 -44
  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/build-support/install-cpp-client.sh +66 -0
  11. package/{pulsar-test-service-start.sh → build-support/pulsar-test-container-start.sh} +11 -21
  12. package/build-support/pulsar-test-service-start.sh +37 -0
  13. package/build-support/pulsar-test-service-stop.sh +32 -0
  14. package/{.github/workflows/nodejs.yml → build-support/sign-files.sh} +13 -12
  15. package/build-support/stage-release.sh +44 -0
  16. package/dependencies.yaml +28 -0
  17. package/docs/release-process.md +242 -0
  18. package/examples/consumer.js +1 -1
  19. package/examples/consumer_listener.js +1 -1
  20. package/examples/consumer_tls_auth.js +1 -1
  21. package/examples/custom_logger.js +60 -0
  22. package/examples/encryption-consumer.js +1 -1
  23. package/examples/encryption-producer.js +1 -1
  24. package/examples/producer.js +1 -1
  25. package/examples/producer_tls_auth.js +1 -1
  26. package/examples/reader.js +1 -1
  27. package/examples/reader_listener.js +1 -1
  28. package/index.d.ts +7 -0
  29. package/index.js +2 -1
  30. package/package.json +15 -7
  31. package/pkg/build-napi-inside-docker.sh +31 -0
  32. package/pkg/linux_glibc/Dockerfile +33 -0
  33. package/pkg/linux_musl/Dockerfile +32 -0
  34. package/pkg/load_test.js +30 -0
  35. package/pkg/mac/build-cpp-deps-lib.sh +186 -0
  36. package/pkg/mac/build-cpp-lib.sh +51 -0
  37. package/pkg/mac/common.sh +37 -0
  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/Consumer.cc +72 -4
  45. package/src/Consumer.h +2 -0
  46. package/src/ConsumerConfig.cc +21 -0
  47. package/src/ProducerConfig.cc +6 -0
  48. package/src/Reader.cc +51 -1
  49. package/src/Reader.h +2 -0
  50. package/src/pulsar-binding.js +8 -0
  51. package/tests/conf/standalone.conf +6 -0
  52. package/tests/end_to_end.test.js +212 -0
  53. package/{docker-tests.sh → tests/run-unit-tests.sh} +10 -13
  54. package/pulsar-version.txt +0 -1
  55. package/run-unit-tests.sh +0 -44
@@ -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
  })();
@@ -18,21 +18,18 @@
18
18
  # under the License.
19
19
  #
20
20
 
21
+ set -e
22
+
21
23
  ROOT_DIR=${ROOT_DIR:-$(git rev-parse --show-toplevel)}
22
24
  cd $ROOT_DIR
23
25
 
24
- BUILD_IMAGE_NAME="${BUILD_IMAGE_NAME:-apachepulsar/pulsar-build}"
25
- BUILD_IMAGE_VERSION="${BUILD_IMAGE_VERSION:-ubuntu-20.04}"
26
-
27
- IMAGE="$BUILD_IMAGE_NAME:$BUILD_IMAGE_VERSION"
28
-
29
- echo "---- Testing Pulsar node client using image $IMAGE"
26
+ # install pulsar cpp client pkg
27
+ build-support/install-cpp-client.sh
30
28
 
31
- docker pull $IMAGE
32
-
33
- TARGET_DIR=/pulsar-client-node
34
- DOCKER_CMD="docker run -i -e ROOT_DIR=$TARGET_DIR -v $ROOT_DIR:$TARGET_DIR $IMAGE"
29
+ cd $ROOT_DIR
30
+ build-support/pulsar-test-service-start.sh
31
+ npm install && npm run lint && npm run dtslint && npm run build && npm run test
32
+ RES=$?
33
+ build-support/pulsar-test-service-stop.sh
35
34
 
36
- # Start Pulsar standalone instance
37
- # and execute the tests
38
- $DOCKER_CMD bash -c "cd /pulsar-client-node && ./run-unit-tests.sh"
35
+ exit $RES
@@ -1 +0,0 @@
1
- 2.10.1
package/run-unit-tests.sh DELETED
@@ -1,44 +0,0 @@
1
- #!/bin/bash
2
- #
3
- # Licensed to the Apache Software Foundation (ASF) under one
4
- # or more contributor license agreements. See the NOTICE file
5
- # distributed with this work for additional information
6
- # regarding copyright ownership. The ASF licenses this file
7
- # to you under the Apache License, Version 2.0 (the
8
- # "License"); you may not use this file except in compliance
9
- # with the License. You may obtain a copy of the License at
10
- #
11
- # http://www.apache.org/licenses/LICENSE-2.0
12
- #
13
- # Unless required by applicable law or agreed to in writing,
14
- # software distributed under the License is distributed on an
15
- # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- # KIND, either express or implied. See the License for the
17
- # specific language governing permissions and limitations
18
- # under the License.
19
- #
20
-
21
- set -e
22
-
23
- ROOT_DIR=${ROOT_DIR:-$(git rev-parse --show-toplevel)}
24
- cd $ROOT_DIR
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
38
-
39
- ./pulsar-test-service-start.sh
40
- npm install && npm run lint && npm run dtslint && npm run build && npm run test
41
- RES=$?
42
- ./pulsar-test-service-stop.sh
43
-
44
- exit $RES