pulsar-client 1.4.0 → 1.6.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/README.md CHANGED
@@ -42,17 +42,45 @@ Compatibility between each version of the Node.js client and the C++ client is a
42
42
 
43
43
  | Node.js client | C++ client |
44
44
  |----------------|----------------|
45
- | 1.0.0 | 2.3.0 or later |
46
- | 1.1.0 | 2.4.0 or later |
47
- | 1.2.0 | 2.5.0 or later |
48
- | 1.3.0 | 2.7.0 or later |
49
- | 1.4.0 | 2.8.0 or later |
45
+ | 1.0.x | 2.3.0 or later |
46
+ | 1.1.x | 2.4.0 or later |
47
+ | 1.2.x | 2.5.0 or later |
48
+ | 1.3.x | 2.7.0 or later |
49
+ | 1.4.x - 1.5.x | 2.8.0 or later |
50
50
 
51
51
  If an incompatible version of the C++ client is installed, you may fail to build or run this library.
52
52
 
53
53
  ## How to install
54
54
 
55
- ### Please install pulsar-client in your project:
55
+ ### Install on windows
56
+
57
+ 1. Build the Pulsar C++ client on windows.
58
+
59
+ ```shell
60
+ cmake \
61
+ -A x64 \
62
+ -DBUILD_PYTHON_WRAPPER=OFF -DBUILD_TESTS=OFF \
63
+ -DVCPKG_TRIPLET=x64-windows \
64
+ -DCMAKE_BUILD_TYPE=Release \
65
+ -S .
66
+ cmake --config Release
67
+ ```
68
+
69
+ 2. Set the variable `PULSAR_CPP_DIR` with the `pulsar-client-cpp` path in a Windows command tool.
70
+
71
+ ```shell
72
+ # for example
73
+ set PULSAR_CPP_DIR=C:\pulsar\pulsar-client-cpp
74
+ ```
75
+
76
+ 3. Set the variable `OS_ARCH` in a Windows command tool, `OS_ARCH` is related to the configuration of VCPKG_TRIPLET on the command line above.(Optional)
77
+
78
+ ```shell
79
+ set OS_ARCH=x64-windows
80
+ ```
81
+
82
+
83
+ ### Install pulsar-client to your project
56
84
 
57
85
  ```shell
58
86
  $ npm install pulsar-client
@@ -72,6 +100,10 @@ $ cd pulsar-client-node
72
100
  $ npm install
73
101
  ```
74
102
 
103
+ > **Note**
104
+ >
105
+ > If you build `pulsar-client-node on` windows, you need to set the variable `PULSAR_CPP_DIR` first, then install npm (run the command `npm install`) in a Windows command-line tool.
106
+
75
107
  ### Rebuild Pulsar client library:
76
108
 
77
109
  ```shell
package/binding.gyp CHANGED
@@ -18,14 +18,24 @@
18
18
  #
19
19
 
20
20
  {
21
+ 'conditions': [
22
+ ['OS=="win"', {
23
+ 'variables': {
24
+ 'pulsar_cpp_dir%': '<!(echo %PULSAR_CPP_DIR%)',
25
+ 'os_arch%': '<!(echo %OS_ARCH%)',
26
+ },
27
+ }]
28
+ ],
21
29
  "targets": [
22
30
  {
23
31
  "target_name": "Pulsar",
32
+ "cflags_cc": ["-std=gnu++11"],
24
33
  "cflags!": ["-fno-exceptions"],
25
- "cflags_cc!": ["-fno-exceptions"],
26
- "include_dirs": ["<!@(node -p \"require('node-addon-api').include\")"],
27
- "dependencies": ["<!@(node -p \"require('node-addon-api').gyp\")"],
28
- "defines": ["NAPI_DISABLE_CPP_EXCEPTIONS"],
34
+ "cflags_cc!": ["-fno-exceptions", "-std=gnu++14", "-std=gnu++17"],
35
+ "include_dirs": [
36
+ "<!@(node -p \"require('node-addon-api').include\")",
37
+ ],
38
+ "defines": ["NAPI_VERSION=4", "NAPI_DISABLE_CPP_EXCEPTIONS=1"],
29
39
  "sources": [
30
40
  "src/addon.cc",
31
41
  "src/Message.cc",
@@ -39,7 +49,42 @@
39
49
  "src/Reader.cc",
40
50
  "src/ReaderConfig.cc",
41
51
  ],
42
- "libraries": ["-lpulsar"],
52
+ 'conditions': [
53
+ ['OS=="win"', {
54
+ "include_dirs": [
55
+ "<(pulsar_cpp_dir)\include",
56
+ ],
57
+ "libraries": [
58
+ "-l<(pulsar_cpp_dir)\\lib\Release\pulsar.lib"
59
+ ],
60
+ "dependencies": [
61
+ "<!(node -p \"require('node-addon-api').gyp\")"
62
+ ],
63
+ "copies": [
64
+ {
65
+ "destination": "<(PRODUCT_DIR)",
66
+ "files": [
67
+ "<(pulsar_cpp_dir)\\lib\Release\pulsar.dll",
68
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcurl.dll",
69
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libprotobuf.dll",
70
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libssl-1_1-x64.dll",
71
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcrypto-1_1-x64.dll",
72
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\dl.dll",
73
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\snappy.dll",
74
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zlib1.dll",
75
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zstd.dll",
76
+ ]
77
+ }
78
+ ]
79
+ }, { # 'OS!="win"'
80
+ "libraries": [
81
+ "-lpulsar",
82
+ ],
83
+ "dependencies": [
84
+ "<!@(node -p \"require('node-addon-api').gyp\")"
85
+ ],
86
+ }]
87
+ ]
43
88
  }
44
89
  ]
45
90
  }
package/index.d.ts CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  export interface ClientConfig {
22
22
  serviceUrl: string;
23
- authentication?: AuthenticationTls | AuthenticationAthenz | AuthenticationToken;
23
+ authentication?: AuthenticationTls | AuthenticationAthenz | AuthenticationToken | AuthenticationOauth2;
24
24
  operationTimeoutSeconds?: number;
25
25
  ioThreads?: number;
26
26
  messageListenerThreads?: number;
@@ -175,6 +175,18 @@ export class AuthenticationToken {
175
175
  constructor(params: { token: string });
176
176
  }
177
177
 
178
+ export class AuthenticationOauth2 {
179
+ constructor(params: {
180
+ type: string;
181
+ issuer_url: string;
182
+ client_id?: string;
183
+ client_secret?: string;
184
+ private_key?: string;
185
+ audience?: string;
186
+ scope?: string;
187
+ });
188
+ }
189
+
178
190
  export enum LogLevel {
179
191
  DEBUG = 0,
180
192
  INFO = 1,
package/index.js CHANGED
@@ -21,6 +21,7 @@ const PulsarBinding = require('bindings')('Pulsar');
21
21
  const AuthenticationTls = require('./src/AuthenticationTls.js');
22
22
  const AuthenticationAthenz = require('./src/AuthenticationAthenz.js');
23
23
  const AuthenticationToken = require('./src/AuthenticationToken.js');
24
+ const AuthenticationOauth2 = require('./src/AuthenticationOauth2.js');
24
25
 
25
26
  const LogLevel = {
26
27
  DEBUG: 0,
@@ -36,6 +37,7 @@ const Pulsar = {
36
37
  AuthenticationTls,
37
38
  AuthenticationAthenz,
38
39
  AuthenticationToken,
40
+ AuthenticationOauth2,
39
41
  LogLevel,
40
42
  };
41
43
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pulsar-client",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Pulsar Node.js client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -37,24 +37,24 @@
37
37
  "clang-format": "^1.4.0",
38
38
  "commander": "^6.1.0",
39
39
  "delay": "^4.4.0",
40
- "dtslint": "^4.0.6",
40
+ "dtslint": "^3.4.2",
41
41
  "eslint": "^7.8.1",
42
42
  "eslint-config-airbnb-base": "^14.2.0",
43
43
  "eslint-plugin-import": "^2.22.0",
44
44
  "eslint-plugin-jest": "^24.3.6",
45
- "grunt": "^1.3.0",
45
+ "grunt": "^1.4.1",
46
46
  "grunt-license-report": "^0.0.8",
47
47
  "hdr-histogram-js": "^2.0.1",
48
- "jest": "^26.4.2",
48
+ "jest": "^27.2.4",
49
49
  "license-check-and-add": "^2.3.6",
50
50
  "lodash": "^4.17.21",
51
51
  "typescript": "^4.1.3"
52
52
  },
53
53
  "dependencies": {
54
+ "@mapbox/node-pre-gyp": "^1.0.7",
54
55
  "bindings": "^1.5.0",
55
- "node-addon-api": "^3.0.0",
56
- "node-gyp": "^7.1.0",
57
- "node-pre-gyp": "^0.15.0"
56
+ "node-addon-api": "^3.2.1",
57
+ "node-gyp": "^8.4.1"
58
58
  },
59
59
  "binary": {
60
60
  "module_name": "libpulsar",
@@ -80,6 +80,13 @@ Authentication::Authentication(const Napi::CallbackInfo &info)
80
80
  return;
81
81
  }
82
82
  this->cAuthentication = pulsar_authentication_athenz_create(info[1].ToString().Utf8Value().c_str());
83
+ } else if (authMethod == "oauth2") {
84
+ if (info.Length() < 2 || !info[1].IsString()) {
85
+ Napi::Error::New(env, "Authentication parameter must be a JSON string for oauth2")
86
+ .ThrowAsJavaScriptException();
87
+ return;
88
+ }
89
+ this->cAuthentication = pulsar_authentication_oauth2_create(info[1].ToString().Utf8Value().c_str());
83
90
  } else {
84
91
  Napi::Error::New(env, "Unsupported authentication method").ThrowAsJavaScriptException();
85
92
  return;
@@ -0,0 +1,28 @@
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 PulsarBinding = require('bindings')('Pulsar');
20
+
21
+ class AuthenticationOauth2 {
22
+ constructor(params) {
23
+ const paramsStr = (typeof params === 'object') ? JSON.stringify(params) : params;
24
+ this.binding = new PulsarBinding.Authentication('oauth2', paramsStr);
25
+ }
26
+ }
27
+
28
+ module.exports = AuthenticationOauth2;
package/src/Consumer.cc CHANGED
@@ -164,6 +164,12 @@ class ConsumerNewInstanceWorker : public Napi::AsyncWorker {
164
164
 
165
165
  consumer->SetCConsumer(this->consumerWrapper);
166
166
  consumer->SetListenerCallback(this->listener);
167
+
168
+ if (this->listener) {
169
+ // resume to enable MessageListener function callback
170
+ resume_message_listener(this->consumerWrapper->cConsumer);
171
+ }
172
+
167
173
  this->deferred.Resolve(obj);
168
174
  }
169
175
  void OnError(const Napi::Error &e) { this->deferred.Reject(Napi::Error::New(Env(), e.Message()).Value()); }
@@ -183,6 +189,11 @@ class ConsumerNewInstanceWorker : public Napi::AsyncWorker {
183
189
  } else {
184
190
  worker->consumerWrapper->cConsumer = consumer;
185
191
  worker->listener = worker->consumerConfig->GetListenerCallback();
192
+
193
+ if (worker->listener) {
194
+ // pause, will resume in OnOK, to prevent MessageListener get a nullptr of consumer
195
+ pulsar_consumer_pause_message_listener(consumer);
196
+ }
186
197
  }
187
198
 
188
199
  delete worker->consumerConfig;
package/tslint.json CHANGED
@@ -2,6 +2,7 @@
2
2
  "extends": "dtslint/dtslint.json",
3
3
  "rules": {
4
4
  "no-unnecessary-class": false,
5
- "no-relative-import-in-test": false
5
+ "no-relative-import-in-test": false,
6
+ "strict-export-declare-modifiers": false
6
7
  }
7
8
  }
package/tstest.ts CHANGED
@@ -39,6 +39,23 @@ import Pulsar = require('./index');
39
39
  tokenExpirationTime: '3600',
40
40
  });
41
41
 
42
+ const authOauth2PrivateKey: Pulsar.AuthenticationOauth2 = new Pulsar.AuthenticationOauth2({
43
+ type: "client_credentials",
44
+ issuer_url: "issuer-url",
45
+ private_key: "credentials-file-path",
46
+ audience: "audience",
47
+ scope: "your-scope",
48
+ });
49
+
50
+ const authOauth2ClientId: Pulsar.AuthenticationOauth2 = new Pulsar.AuthenticationOauth2({
51
+ type: "client_credentials",
52
+ issuer_url: "issuer-url",
53
+ client_id: "client-id",
54
+ client_secret: "client-secret",
55
+ audience: "audience",
56
+ scope: "scope"
57
+ });
58
+
42
59
  const authToken: Pulsar.AuthenticationToken = new Pulsar.AuthenticationToken({
43
60
  token: 'foobar',
44
61
  });