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.
- package/.asf.yaml +8 -1
- package/.github/PULL_REQUEST_TEMPLATE.md +85 -0
- package/.github/workflows/ci-build-release-napi.yml +213 -0
- package/.github/workflows/ci-pr-validation.yml +233 -0
- package/README.md +91 -68
- package/binding.gyp +48 -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/{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 +271 -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 +16 -13
- package/pkg/linux/Dockerfile_linux_glibc +35 -0
- package/pkg/linux/Dockerfile_linux_musl +32 -0
- package/pkg/linux/build-napi-inside-docker.sh +31 -0
- package/pkg/linux/download-cpp-client.sh +65 -0
- package/pkg/load_test.js +34 -0
- package/pkg/mac/build-cpp-deps-lib.sh +186 -0
- package/pkg/mac/build-cpp-lib.sh +48 -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 +26 -0
- package/tests/conf/standalone.conf +6 -0
- package/tests/consumer.test.js +2 -2
- package/tests/docker-load-test.sh +35 -0
- package/tests/end_to_end.test.js +214 -2
- package/tests/load-test.sh +43 -0
- package/tests/producer.test.js +2 -2
- package/{run-unit-tests.sh → tests/run-unit-tests.sh} +6 -15
- package/pulsar-version.txt +0 -1
package/src/Client.cc
CHANGED
|
@@ -17,11 +17,12 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
#include "Authentication.h"
|
|
20
21
|
#include "Client.h"
|
|
21
22
|
#include "Consumer.h"
|
|
22
23
|
#include "Producer.h"
|
|
23
24
|
#include "Reader.h"
|
|
24
|
-
#include "
|
|
25
|
+
#include "ThreadSafeDeferred.h"
|
|
25
26
|
#include <pulsar/c/client.h>
|
|
26
27
|
#include <pulsar/c/client_configuration.h>
|
|
27
28
|
#include <pulsar/c/result.h>
|
|
@@ -40,6 +41,34 @@ static const std::string CFG_TLS_ALLOW_INSECURE = "tlsAllowInsecureConnection";
|
|
|
40
41
|
static const std::string CFG_STATS_INTERVAL = "statsIntervalInSeconds";
|
|
41
42
|
static const std::string CFG_LOG = "log";
|
|
42
43
|
|
|
44
|
+
LogCallback *Client::logCallback = nullptr;
|
|
45
|
+
|
|
46
|
+
void Client::SetLogHandler(const Napi::CallbackInfo &info) {
|
|
47
|
+
Napi::Env env = info.Env();
|
|
48
|
+
Napi::HandleScope scope(env);
|
|
49
|
+
Napi::Value jsFunction = info[0];
|
|
50
|
+
|
|
51
|
+
if (jsFunction.IsNull()) {
|
|
52
|
+
if (Client::logCallback != nullptr) {
|
|
53
|
+
Client::logCallback->callback.Release();
|
|
54
|
+
delete Client::logCallback;
|
|
55
|
+
Client::logCallback = nullptr;
|
|
56
|
+
}
|
|
57
|
+
} else if (jsFunction.IsFunction()) {
|
|
58
|
+
Napi::ThreadSafeFunction logFunction =
|
|
59
|
+
Napi::ThreadSafeFunction::New(env, jsFunction.As<Napi::Function>(), "Pulsar Logging", 0, 1);
|
|
60
|
+
logFunction.Unref(env);
|
|
61
|
+
if (Client::logCallback != nullptr) {
|
|
62
|
+
Client::logCallback->callback.Release();
|
|
63
|
+
} else {
|
|
64
|
+
Client::logCallback = new LogCallback();
|
|
65
|
+
}
|
|
66
|
+
Client::logCallback->callback = std::move(logFunction);
|
|
67
|
+
} else {
|
|
68
|
+
Napi::Error::New(env, "Client log handler must be a function or null").ThrowAsJavaScriptException();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
43
72
|
Napi::FunctionReference Client::constructor;
|
|
44
73
|
|
|
45
74
|
Napi::Object Client::Init(Napi::Env env, Napi::Object exports) {
|
|
@@ -47,7 +76,8 @@ Napi::Object Client::Init(Napi::Env env, Napi::Object exports) {
|
|
|
47
76
|
|
|
48
77
|
Napi::Function func = DefineClass(
|
|
49
78
|
env, "Client",
|
|
50
|
-
{
|
|
79
|
+
{StaticMethod("setLogHandler", &Client::SetLogHandler),
|
|
80
|
+
InstanceMethod("createProducer", &Client::CreateProducer),
|
|
51
81
|
InstanceMethod("subscribe", &Client::Subscribe), InstanceMethod("createReader", &Client::CreateReader),
|
|
52
82
|
InstanceMethod("close", &Client::Close)});
|
|
53
83
|
|
|
@@ -72,95 +102,95 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Client>(info)
|
|
|
72
102
|
}
|
|
73
103
|
Napi::String serviceUrl = clientConfig.Get(CFG_SERVICE_URL).ToString();
|
|
74
104
|
|
|
75
|
-
|
|
105
|
+
this->cClientConfig = std::shared_ptr<pulsar_client_configuration_t>(pulsar_client_configuration_create(),
|
|
106
|
+
pulsar_client_configuration_free);
|
|
107
|
+
|
|
108
|
+
// The logger can only be set once per process, so we will take control of it
|
|
109
|
+
pulsar_client_configuration_set_logger(cClientConfig.get(), &LogMessage, nullptr);
|
|
76
110
|
|
|
111
|
+
// log config option should be deprecated in favour of static setLogHandler method
|
|
77
112
|
if (clientConfig.Has(CFG_LOG) && clientConfig.Get(CFG_LOG).IsFunction()) {
|
|
78
113
|
Napi::ThreadSafeFunction logFunction = Napi::ThreadSafeFunction::New(
|
|
79
114
|
env, clientConfig.Get(CFG_LOG).As<Napi::Function>(), "Pulsar Logging", 0, 1);
|
|
80
|
-
|
|
81
|
-
this->logCallback->callback = logFunction;
|
|
115
|
+
logFunction.Unref(env);
|
|
82
116
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
117
|
+
if (Client::logCallback != nullptr) {
|
|
118
|
+
Client::logCallback->callback.Release();
|
|
119
|
+
} else {
|
|
120
|
+
Client::logCallback = new LogCallback();
|
|
121
|
+
}
|
|
122
|
+
Client::logCallback->callback = std::move(logFunction);
|
|
86
123
|
}
|
|
87
124
|
|
|
88
125
|
if (clientConfig.Has(CFG_AUTH) && clientConfig.Get(CFG_AUTH).IsObject()) {
|
|
89
126
|
Napi::Object obj = clientConfig.Get(CFG_AUTH).ToObject();
|
|
90
127
|
if (obj.Has(CFG_AUTH_PROP) && obj.Get(CFG_AUTH_PROP).IsObject()) {
|
|
91
128
|
Authentication *auth = Authentication::Unwrap(obj.Get(CFG_AUTH_PROP).ToObject());
|
|
92
|
-
pulsar_client_configuration_set_auth(cClientConfig, auth->GetCAuthentication());
|
|
129
|
+
pulsar_client_configuration_set_auth(cClientConfig.get(), auth->GetCAuthentication());
|
|
93
130
|
}
|
|
94
131
|
}
|
|
95
132
|
|
|
96
133
|
if (clientConfig.Has(CFG_OP_TIMEOUT) && clientConfig.Get(CFG_OP_TIMEOUT).IsNumber()) {
|
|
97
134
|
int32_t operationTimeoutSeconds = clientConfig.Get(CFG_OP_TIMEOUT).ToNumber().Int32Value();
|
|
98
135
|
if (operationTimeoutSeconds > 0) {
|
|
99
|
-
pulsar_client_configuration_set_operation_timeout_seconds(cClientConfig, operationTimeoutSeconds);
|
|
136
|
+
pulsar_client_configuration_set_operation_timeout_seconds(cClientConfig.get(), operationTimeoutSeconds);
|
|
100
137
|
}
|
|
101
138
|
}
|
|
102
139
|
|
|
103
140
|
if (clientConfig.Has(CFG_IO_THREADS) && clientConfig.Get(CFG_IO_THREADS).IsNumber()) {
|
|
104
141
|
int32_t ioThreads = clientConfig.Get(CFG_IO_THREADS).ToNumber().Int32Value();
|
|
105
142
|
if (ioThreads > 0) {
|
|
106
|
-
pulsar_client_configuration_set_io_threads(cClientConfig, ioThreads);
|
|
143
|
+
pulsar_client_configuration_set_io_threads(cClientConfig.get(), ioThreads);
|
|
107
144
|
}
|
|
108
145
|
}
|
|
109
146
|
|
|
110
147
|
if (clientConfig.Has(CFG_LISTENER_THREADS) && clientConfig.Get(CFG_LISTENER_THREADS).IsNumber()) {
|
|
111
148
|
int32_t messageListenerThreads = clientConfig.Get(CFG_LISTENER_THREADS).ToNumber().Int32Value();
|
|
112
149
|
if (messageListenerThreads > 0) {
|
|
113
|
-
pulsar_client_configuration_set_message_listener_threads(cClientConfig, messageListenerThreads);
|
|
150
|
+
pulsar_client_configuration_set_message_listener_threads(cClientConfig.get(), messageListenerThreads);
|
|
114
151
|
}
|
|
115
152
|
}
|
|
116
153
|
|
|
117
154
|
if (clientConfig.Has(CFG_CONCURRENT_LOOKUP) && clientConfig.Get(CFG_CONCURRENT_LOOKUP).IsNumber()) {
|
|
118
155
|
int32_t concurrentLookupRequest = clientConfig.Get(CFG_CONCURRENT_LOOKUP).ToNumber().Int32Value();
|
|
119
156
|
if (concurrentLookupRequest > 0) {
|
|
120
|
-
pulsar_client_configuration_set_concurrent_lookup_request(cClientConfig, concurrentLookupRequest);
|
|
157
|
+
pulsar_client_configuration_set_concurrent_lookup_request(cClientConfig.get(), concurrentLookupRequest);
|
|
121
158
|
}
|
|
122
159
|
}
|
|
123
160
|
|
|
124
161
|
if (clientConfig.Has(CFG_USE_TLS) && clientConfig.Get(CFG_USE_TLS).IsBoolean()) {
|
|
125
162
|
Napi::Boolean useTls = clientConfig.Get(CFG_USE_TLS).ToBoolean();
|
|
126
|
-
pulsar_client_configuration_set_use_tls(cClientConfig, useTls.Value());
|
|
163
|
+
pulsar_client_configuration_set_use_tls(cClientConfig.get(), useTls.Value());
|
|
127
164
|
}
|
|
128
165
|
|
|
129
166
|
if (clientConfig.Has(CFG_TLS_TRUST_CERT) && clientConfig.Get(CFG_TLS_TRUST_CERT).IsString()) {
|
|
130
167
|
Napi::String tlsTrustCertsFilePath = clientConfig.Get(CFG_TLS_TRUST_CERT).ToString();
|
|
131
|
-
pulsar_client_configuration_set_tls_trust_certs_file_path(cClientConfig,
|
|
168
|
+
pulsar_client_configuration_set_tls_trust_certs_file_path(cClientConfig.get(),
|
|
132
169
|
tlsTrustCertsFilePath.Utf8Value().c_str());
|
|
133
170
|
}
|
|
134
171
|
|
|
135
172
|
if (clientConfig.Has(CFG_TLS_VALIDATE_HOSTNAME) &&
|
|
136
173
|
clientConfig.Get(CFG_TLS_VALIDATE_HOSTNAME).IsBoolean()) {
|
|
137
174
|
Napi::Boolean tlsValidateHostname = clientConfig.Get(CFG_TLS_VALIDATE_HOSTNAME).ToBoolean();
|
|
138
|
-
pulsar_client_configuration_set_validate_hostname(cClientConfig, tlsValidateHostname.Value());
|
|
175
|
+
pulsar_client_configuration_set_validate_hostname(cClientConfig.get(), tlsValidateHostname.Value());
|
|
139
176
|
}
|
|
140
177
|
|
|
141
178
|
if (clientConfig.Has(CFG_TLS_ALLOW_INSECURE) && clientConfig.Get(CFG_TLS_ALLOW_INSECURE).IsBoolean()) {
|
|
142
179
|
Napi::Boolean tlsAllowInsecureConnection = clientConfig.Get(CFG_TLS_ALLOW_INSECURE).ToBoolean();
|
|
143
|
-
pulsar_client_configuration_set_tls_allow_insecure_connection(cClientConfig,
|
|
180
|
+
pulsar_client_configuration_set_tls_allow_insecure_connection(cClientConfig.get(),
|
|
144
181
|
tlsAllowInsecureConnection.Value());
|
|
145
182
|
}
|
|
146
183
|
|
|
147
184
|
if (clientConfig.Has(CFG_STATS_INTERVAL) && clientConfig.Get(CFG_STATS_INTERVAL).IsNumber()) {
|
|
148
185
|
uint32_t statsIntervalInSeconds = clientConfig.Get(CFG_STATS_INTERVAL).ToNumber().Uint32Value();
|
|
149
|
-
pulsar_client_configuration_set_stats_interval_in_seconds(cClientConfig, statsIntervalInSeconds);
|
|
186
|
+
pulsar_client_configuration_set_stats_interval_in_seconds(cClientConfig.get(), statsIntervalInSeconds);
|
|
150
187
|
}
|
|
151
188
|
|
|
152
|
-
this->cClient =
|
|
153
|
-
|
|
154
|
-
this->Ref();
|
|
189
|
+
this->cClient = std::shared_ptr<pulsar_client_t>(
|
|
190
|
+
pulsar_client_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free);
|
|
155
191
|
}
|
|
156
192
|
|
|
157
|
-
Client::~Client() {
|
|
158
|
-
pulsar_client_free(this->cClient);
|
|
159
|
-
if (this->logCallback != nullptr) {
|
|
160
|
-
this->logCallback->callback.Release();
|
|
161
|
-
this->logCallback = nullptr;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
193
|
+
Client::~Client() {}
|
|
164
194
|
|
|
165
195
|
Napi::Value Client::CreateProducer(const Napi::CallbackInfo &info) {
|
|
166
196
|
return Producer::NewInstance(info, this->cClient);
|
|
@@ -183,8 +213,13 @@ void LogMessageProxy(Napi::Env env, Napi::Function jsCallback, struct LogMessage
|
|
|
183
213
|
jsCallback.Call({logLevel, file, line, message});
|
|
184
214
|
}
|
|
185
215
|
|
|
186
|
-
void LogMessage(pulsar_logger_level_t level, const char *file, int line, const char *message,
|
|
187
|
-
|
|
216
|
+
void Client::LogMessage(pulsar_logger_level_t level, const char *file, int line, const char *message,
|
|
217
|
+
void *ctx) {
|
|
218
|
+
LogCallback *logCallback = Client::logCallback;
|
|
219
|
+
|
|
220
|
+
if (logCallback == nullptr) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
188
223
|
|
|
189
224
|
if (logCallback->callback.Acquire() != napi_ok) {
|
|
190
225
|
return;
|
|
@@ -196,33 +231,24 @@ void LogMessage(pulsar_logger_level_t level, const char *file, int line, const c
|
|
|
196
231
|
logCallback->callback.Release();
|
|
197
232
|
}
|
|
198
233
|
|
|
199
|
-
class ClientCloseWorker : public Napi::AsyncWorker {
|
|
200
|
-
public:
|
|
201
|
-
ClientCloseWorker(const Napi::Promise::Deferred &deferred, pulsar_client_t *cClient)
|
|
202
|
-
: AsyncWorker(Napi::Function::New(deferred.Promise().Env(), [](const Napi::CallbackInfo &info) {})),
|
|
203
|
-
deferred(deferred),
|
|
204
|
-
cClient(cClient) {}
|
|
205
|
-
~ClientCloseWorker() {}
|
|
206
|
-
void Execute() {
|
|
207
|
-
pulsar_result result = pulsar_client_close(this->cClient);
|
|
208
|
-
if (result != pulsar_result_Ok) SetError(pulsar_result_str(result));
|
|
209
|
-
}
|
|
210
|
-
void OnOK() { this->deferred.Resolve(Env().Null()); }
|
|
211
|
-
void OnError(const Napi::Error &e) {
|
|
212
|
-
this->deferred.Reject(
|
|
213
|
-
Napi::Error::New(Env(), std::string("Failed to close client: ") + e.Message()).Value());
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
private:
|
|
217
|
-
Napi::Promise::Deferred deferred;
|
|
218
|
-
pulsar_client_t *cClient;
|
|
219
|
-
};
|
|
220
|
-
|
|
221
234
|
Napi::Value Client::Close(const Napi::CallbackInfo &info) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
235
|
+
auto deferred = ThreadSafeDeferred::New(Env());
|
|
236
|
+
auto ctx = new ExtDeferredContext(deferred);
|
|
237
|
+
|
|
238
|
+
pulsar_client_close_async(
|
|
239
|
+
this->cClient.get(),
|
|
240
|
+
[](pulsar_result result, void *ctx) {
|
|
241
|
+
auto deferredContext = static_cast<ExtDeferredContext *>(ctx);
|
|
242
|
+
auto deferred = deferredContext->deferred;
|
|
243
|
+
delete deferredContext;
|
|
244
|
+
|
|
245
|
+
if (result != pulsar_result_Ok) {
|
|
246
|
+
deferred->Reject(std::string("Failed to close client: ") + pulsar_result_str(result));
|
|
247
|
+
} else {
|
|
248
|
+
deferred->Resolve(THREADSAFE_DEFERRED_RESOLVER(env.Null()));
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
ctx);
|
|
252
|
+
|
|
253
|
+
return deferred->Promise();
|
|
228
254
|
}
|
package/src/Client.h
CHANGED
|
@@ -37,20 +37,22 @@ struct LogCallback {
|
|
|
37
37
|
Napi::ThreadSafeFunction callback;
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
void LogMessage(pulsar_logger_level_t level, const char *file, int line, const char *message, void *ctx);
|
|
41
|
-
|
|
42
40
|
class Client : public Napi::ObjectWrap<Client> {
|
|
43
41
|
public:
|
|
44
42
|
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
43
|
+
static void SetLogHandler(const Napi::CallbackInfo &info);
|
|
45
44
|
|
|
46
45
|
Client(const Napi::CallbackInfo &info);
|
|
47
46
|
~Client();
|
|
48
47
|
|
|
49
48
|
private:
|
|
49
|
+
static LogCallback *logCallback;
|
|
50
50
|
static Napi::FunctionReference constructor;
|
|
51
|
-
pulsar_client_t
|
|
52
|
-
|
|
51
|
+
std::shared_ptr<pulsar_client_t> cClient;
|
|
52
|
+
std::shared_ptr<pulsar_client_configuration_t> cClientConfig;
|
|
53
53
|
|
|
54
|
+
static void LogMessage(pulsar_logger_level_t level, const char *file, int line, const char *message,
|
|
55
|
+
void *ctx);
|
|
54
56
|
Napi::Value CreateProducer(const Napi::CallbackInfo &info);
|
|
55
57
|
Napi::Value Subscribe(const Napi::CallbackInfo &info);
|
|
56
58
|
Napi::Value CreateReader(const Napi::CallbackInfo &info);
|