pulsar-client 1.4.1 → 1.6.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.
package/README.md CHANGED
@@ -46,13 +46,64 @@ Compatibility between each version of the Node.js client and the C++ client is a
46
46
  | 1.1.x | 2.4.0 or later |
47
47
  | 1.2.x | 2.5.0 or later |
48
48
  | 1.3.x | 2.7.0 or later |
49
- | 1.4.x | 2.8.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
+
70
+ 2. Set the variable `PULSAR_CPP_DIR` with the `pulsar-client-cpp` path in a Windows command tool.
71
+
72
+ ```shell
73
+ # for example
74
+ set PULSAR_CPP_DIR=C:\pulsar\pulsar-client-cpp
75
+ ```
76
+
77
+ 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)
78
+
79
+ ```shell
80
+ set OS_ARCH=x64-windows
81
+ ```
82
+
83
+ ### Install on mac
84
+
85
+ 1. Install the Pulsar C++ client on mac.
86
+
87
+ ```shell
88
+ brew install libpulsar
89
+ ```
90
+
91
+ 2. Get the installation path of libpulsar
92
+
93
+ ```shell
94
+ brew info libpulsar
95
+ ```
96
+
97
+
98
+ 2. Set the variable `PULSAR_CPP_DIR` with the `pulsar-client-cpp` path in a mac command tool.
99
+
100
+ ```shell
101
+ # for example
102
+ export PULSAR_CPP_DIR=/usr/local/Cellar/libpulsar/2.9.1_1
103
+ ```
104
+
105
+
106
+ ### Install pulsar-client to your project
56
107
 
57
108
  ```shell
58
109
  $ npm install pulsar-client
@@ -72,6 +123,10 @@ $ cd pulsar-client-node
72
123
  $ npm install
73
124
  ```
74
125
 
126
+ > **Note**
127
+ >
128
+ > 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.
129
+
75
130
  ### Rebuild Pulsar client library:
76
131
 
77
132
  ```shell
package/binding.gyp CHANGED
@@ -18,14 +18,29 @@
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
+ ['OS=="mac"', {
29
+ 'variables': {
30
+ 'pulsar_cpp_dir': '<!(echo $PULSAR_CPP_DIR)'
31
+ }
32
+ }]
33
+ ],
21
34
  "targets": [
22
35
  {
23
36
  "target_name": "Pulsar",
37
+ "cflags_cc": ["-std=gnu++11"],
24
38
  "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"],
39
+ "cflags_cc!": ["-fno-exceptions", "-std=gnu++14", "-std=gnu++17"],
40
+ "include_dirs": [
41
+ "<!@(node -p \"require('node-addon-api').include\")",
42
+ ],
43
+ "defines": ["NAPI_VERSION=4", "NAPI_DISABLE_CPP_EXCEPTIONS=1"],
29
44
  "sources": [
30
45
  "src/addon.cc",
31
46
  "src/Message.cc",
@@ -39,7 +54,50 @@
39
54
  "src/Reader.cc",
40
55
  "src/ReaderConfig.cc",
41
56
  ],
42
- "libraries": ["-lpulsar"],
57
+ 'conditions': [
58
+ ['OS=="mac"', {
59
+ "include_dirs": [
60
+ "<(pulsar_cpp_dir)/include",
61
+ ],
62
+ "libraries": [
63
+ "<(pulsar_cpp_dir)/lib/libpulsar.dylib"
64
+ ],
65
+ }],
66
+ ['OS=="win"', {
67
+ "include_dirs": [
68
+ "<(pulsar_cpp_dir)\include",
69
+ ],
70
+ "libraries": [
71
+ "-l<(pulsar_cpp_dir)\\lib\Release\pulsar.lib"
72
+ ],
73
+ "dependencies": [
74
+ "<!(node -p \"require('node-addon-api').gyp\")"
75
+ ],
76
+ "copies": [
77
+ {
78
+ "destination": "<(PRODUCT_DIR)",
79
+ "files": [
80
+ "<(pulsar_cpp_dir)\\lib\Release\pulsar.dll",
81
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcurl.dll",
82
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libprotobuf.dll",
83
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libssl-1_1-x64.dll",
84
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\libcrypto-1_1-x64.dll",
85
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\dl.dll",
86
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\snappy.dll",
87
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zlib1.dll",
88
+ "<(pulsar_cpp_dir)\\vcpkg_installed\\<(os_arch)\\bin\zstd.dll",
89
+ ]
90
+ }
91
+ ]
92
+ }, { # 'OS!="win"'
93
+ "libraries": [
94
+ "-lpulsar",
95
+ ],
96
+ "dependencies": [
97
+ "<!@(node -p \"require('node-addon-api').gyp\")"
98
+ ],
99
+ }]
100
+ ]
43
101
  }
44
102
  ]
45
103
  }
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.1",
3
+ "version": "1.6.1",
4
4
  "description": "Pulsar Node.js client",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -51,10 +51,10 @@
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": "^8.2.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/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
  });