pulsar-client 1.6.2 → 1.8.0-rc.2
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 +225 -0
- package/README.md +87 -68
- package/binding.gyp +41 -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/build-support/install-cpp-client.sh +66 -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 +262 -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/build-napi-inside-docker.sh +31 -0
- package/pkg/linux_glibc/Dockerfile +33 -0
- package/pkg/linux_musl/Dockerfile +32 -0
- package/pkg/load_test.js +30 -0
- package/pkg/mac/build-cpp-deps-lib.sh +186 -0
- package/pkg/mac/build-cpp-lib.sh +51 -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/end_to_end.test.js +214 -2
- package/tests/producer.test.js +2 -2
- package/{run-unit-tests.sh → tests/run-unit-tests.sh} +5 -14
- package/pulsar-version.txt +0 -1
package/src/Producer.cc
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
#include "ProducerConfig.h"
|
|
22
22
|
#include "Message.h"
|
|
23
23
|
#include "MessageId.h"
|
|
24
|
+
#include "ThreadSafeDeferred.h"
|
|
24
25
|
#include <pulsar/c/result.h>
|
|
25
26
|
#include <memory>
|
|
26
27
|
Napi::FunctionReference Producer::constructor;
|
|
@@ -40,169 +41,151 @@ void Producer::Init(Napi::Env env, Napi::Object exports) {
|
|
|
40
41
|
constructor.SuppressDestruct();
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
void Producer::SetCProducer(pulsar_producer_t
|
|
44
|
-
|
|
45
|
-
class ProducerNewInstanceWorker : public Napi::AsyncWorker {
|
|
46
|
-
public:
|
|
47
|
-
ProducerNewInstanceWorker(const Napi::Promise::Deferred &deferred, pulsar_client_t *cClient,
|
|
48
|
-
ProducerConfig *producerConfig)
|
|
49
|
-
: AsyncWorker(Napi::Function::New(deferred.Promise().Env(), [](const Napi::CallbackInfo &info) {})),
|
|
50
|
-
deferred(deferred),
|
|
51
|
-
cClient(cClient),
|
|
52
|
-
producerConfig(producerConfig) {}
|
|
53
|
-
~ProducerNewInstanceWorker() {}
|
|
54
|
-
void Execute() {
|
|
55
|
-
const std::string &topic = this->producerConfig->GetTopic();
|
|
56
|
-
if (topic.empty()) {
|
|
57
|
-
SetError(std::string("Topic is required and must be specified as a string when creating producer"));
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
pulsar_result result = pulsar_client_create_producer(
|
|
62
|
-
this->cClient, topic.c_str(), this->producerConfig->GetCProducerConfig(), &(this->cProducer));
|
|
63
|
-
delete this->producerConfig;
|
|
64
|
-
if (result != pulsar_result_Ok) {
|
|
65
|
-
SetError(std::string("Failed to create producer: ") + pulsar_result_str(result));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
void OnOK() {
|
|
70
|
-
Napi::Object obj = Producer::constructor.New({});
|
|
71
|
-
Producer *producer = Producer::Unwrap(obj);
|
|
72
|
-
producer->SetCProducer(this->cProducer);
|
|
73
|
-
this->deferred.Resolve(obj);
|
|
74
|
-
}
|
|
75
|
-
void OnError(const Napi::Error &e) { this->deferred.Reject(Napi::Error::New(Env(), e.Message()).Value()); }
|
|
44
|
+
void Producer::SetCProducer(std::shared_ptr<pulsar_producer_t> cProducer) { this->cProducer = cProducer; }
|
|
76
45
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
46
|
+
struct ProducerNewInstanceContext {
|
|
47
|
+
ProducerNewInstanceContext(std::shared_ptr<ThreadSafeDeferred> deferred,
|
|
48
|
+
std::shared_ptr<pulsar_client_t> cClient,
|
|
49
|
+
std::shared_ptr<ProducerConfig> producerConfig)
|
|
50
|
+
: deferred(deferred), cClient(cClient), producerConfig(producerConfig){};
|
|
51
|
+
std::shared_ptr<ThreadSafeDeferred> deferred;
|
|
52
|
+
std::shared_ptr<pulsar_client_t> cClient;
|
|
53
|
+
std::shared_ptr<ProducerConfig> producerConfig;
|
|
82
54
|
};
|
|
83
55
|
|
|
84
|
-
Napi::Value Producer::NewInstance(const Napi::CallbackInfo &info, pulsar_client_t
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
ProducerNewInstanceWorker *wk = new ProducerNewInstanceWorker(deferred, cClient, producerConfig);
|
|
89
|
-
wk->Queue();
|
|
90
|
-
return deferred.Promise();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
Producer::Producer(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Producer>(info) {}
|
|
56
|
+
Napi::Value Producer::NewInstance(const Napi::CallbackInfo &info, std::shared_ptr<pulsar_client_t> cClient) {
|
|
57
|
+
auto deferred = ThreadSafeDeferred::New(info.Env());
|
|
58
|
+
auto config = info[0].As<Napi::Object>();
|
|
59
|
+
auto producerConfig = std::make_shared<ProducerConfig>(config);
|
|
94
60
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
deferred(deferred),
|
|
101
|
-
cProducer(cProducer),
|
|
102
|
-
cMessage(cMessage) {}
|
|
103
|
-
~ProducerSendWorker() { pulsar_message_free(this->cMessage); }
|
|
104
|
-
void Execute() {
|
|
105
|
-
pulsar_result result = pulsar_producer_send(this->cProducer, this->cMessage);
|
|
106
|
-
if (result != pulsar_result_Ok) SetError(pulsar_result_str(result));
|
|
107
|
-
}
|
|
108
|
-
void OnOK() {
|
|
109
|
-
Napi::Object messageId = MessageId::NewInstance(pulsar_message_get_message_id(this->cMessage));
|
|
110
|
-
this->deferred.Resolve(messageId);
|
|
111
|
-
}
|
|
112
|
-
void OnError(const Napi::Error &e) {
|
|
113
|
-
this->deferred.Reject(
|
|
114
|
-
Napi::Error::New(Env(), std::string("Failed to send message: ") + e.Message()).Value());
|
|
61
|
+
const std::string &topic = producerConfig->GetTopic();
|
|
62
|
+
if (topic.empty()) {
|
|
63
|
+
deferred->Reject(
|
|
64
|
+
std::string("Topic is required and must be specified as a string when creating producer"));
|
|
65
|
+
return deferred->Promise();
|
|
115
66
|
}
|
|
116
67
|
|
|
117
|
-
|
|
118
|
-
Napi::Promise::Deferred deferred;
|
|
119
|
-
pulsar_producer_t *cProducer;
|
|
120
|
-
pulsar_message_t *cMessage;
|
|
121
|
-
};
|
|
68
|
+
auto ctx = new ProducerNewInstanceContext(deferred, cClient, producerConfig);
|
|
122
69
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
70
|
+
pulsar_client_create_producer_async(
|
|
71
|
+
cClient.get(), topic.c_str(), producerConfig->GetCProducerConfig().get(),
|
|
72
|
+
[](pulsar_result result, pulsar_producer_t *rawProducer, void *ctx) {
|
|
73
|
+
auto instanceContext = static_cast<ProducerNewInstanceContext *>(ctx);
|
|
74
|
+
auto deferred = instanceContext->deferred;
|
|
75
|
+
auto cClient = instanceContext->cClient;
|
|
76
|
+
delete instanceContext;
|
|
130
77
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
: AsyncWorker(Napi::Function::New(deferred.Promise().Env(), [](const Napi::CallbackInfo &info) {})),
|
|
135
|
-
deferred(deferred),
|
|
136
|
-
cProducer(cProducer) {}
|
|
78
|
+
if (result != pulsar_result_Ok) {
|
|
79
|
+
return deferred->Reject(std::string("Failed to create producer: ") + pulsar_result_str(result));
|
|
80
|
+
}
|
|
137
81
|
|
|
138
|
-
|
|
82
|
+
std::shared_ptr<pulsar_producer_t> cProducer(rawProducer, pulsar_producer_free);
|
|
139
83
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
84
|
+
deferred->Resolve([cProducer](const Napi::Env env) {
|
|
85
|
+
Napi::Object obj = Producer::constructor.New({});
|
|
86
|
+
Producer *producer = Producer::Unwrap(obj);
|
|
87
|
+
producer->SetCProducer(cProducer);
|
|
88
|
+
return obj;
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
ctx);
|
|
144
92
|
|
|
145
|
-
|
|
93
|
+
return deferred->Promise();
|
|
94
|
+
}
|
|
146
95
|
|
|
147
|
-
|
|
148
|
-
this->deferred.Reject(
|
|
149
|
-
Napi::Error::New(Env(), std::string("Failed to flush producer: ") + e.Message()).Value());
|
|
150
|
-
}
|
|
96
|
+
Producer::Producer(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Producer>(info) {}
|
|
151
97
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
98
|
+
struct ProducerSendContext {
|
|
99
|
+
ProducerSendContext(std::shared_ptr<ThreadSafeDeferred> deferred,
|
|
100
|
+
std::shared_ptr<pulsar_message_t> cMessage)
|
|
101
|
+
: deferred(deferred), cMessage(cMessage){};
|
|
102
|
+
std::shared_ptr<ThreadSafeDeferred> deferred;
|
|
103
|
+
std::shared_ptr<pulsar_message_t> cMessage;
|
|
155
104
|
};
|
|
156
105
|
|
|
157
|
-
Napi::Value Producer::
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
106
|
+
Napi::Value Producer::Send(const Napi::CallbackInfo &info) {
|
|
107
|
+
auto cMessage = Message::BuildMessage(info[0].As<Napi::Object>());
|
|
108
|
+
auto deferred = ThreadSafeDeferred::New(Env());
|
|
109
|
+
auto ctx = new ProducerSendContext(deferred, cMessage);
|
|
110
|
+
|
|
111
|
+
pulsar_producer_send_async(
|
|
112
|
+
this->cProducer.get(), cMessage.get(),
|
|
113
|
+
[](pulsar_result result, pulsar_message_id_t *msgId, void *ctx) {
|
|
114
|
+
auto producerSendContext = static_cast<ProducerSendContext *>(ctx);
|
|
115
|
+
auto deferred = producerSendContext->deferred;
|
|
116
|
+
auto cMessage = producerSendContext->cMessage;
|
|
117
|
+
delete producerSendContext;
|
|
118
|
+
|
|
119
|
+
std::shared_ptr<pulsar_message_id_t> cMessageId(msgId, pulsar_message_id_free);
|
|
120
|
+
|
|
121
|
+
if (result != pulsar_result_Ok) {
|
|
122
|
+
deferred->Reject(std::string("Failed to send message: ") + pulsar_result_str(result));
|
|
123
|
+
} else {
|
|
124
|
+
deferred->Resolve([cMessageId](const Napi::Env env) { return MessageId::NewInstance(cMessageId); });
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
ctx);
|
|
128
|
+
|
|
129
|
+
return deferred->Promise();
|
|
162
130
|
}
|
|
163
131
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
}
|
|
132
|
+
Napi::Value Producer::Flush(const Napi::CallbackInfo &info) {
|
|
133
|
+
auto deferred = ThreadSafeDeferred::New(Env());
|
|
134
|
+
auto ctx = new ExtDeferredContext(deferred);
|
|
135
|
+
|
|
136
|
+
pulsar_producer_flush_async(
|
|
137
|
+
this->cProducer.get(),
|
|
138
|
+
[](pulsar_result result, void *ctx) {
|
|
139
|
+
auto deferredContext = static_cast<ExtDeferredContext *>(ctx);
|
|
140
|
+
auto deferred = deferredContext->deferred;
|
|
141
|
+
delete deferredContext;
|
|
142
|
+
|
|
143
|
+
if (result != pulsar_result_Ok) {
|
|
144
|
+
deferred->Reject(std::string("Failed to flush producer: ") + pulsar_result_str(result));
|
|
145
|
+
} else {
|
|
146
|
+
deferred->Resolve(THREADSAFE_DEFERRED_RESOLVER(env.Null()));
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
ctx);
|
|
150
|
+
|
|
151
|
+
return deferred->Promise();
|
|
152
|
+
}
|
|
185
153
|
|
|
186
154
|
Napi::Value Producer::Close(const Napi::CallbackInfo &info) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
155
|
+
auto deferred = ThreadSafeDeferred::New(Env());
|
|
156
|
+
auto ctx = new ExtDeferredContext(deferred);
|
|
157
|
+
|
|
158
|
+
pulsar_producer_close_async(
|
|
159
|
+
this->cProducer.get(),
|
|
160
|
+
[](pulsar_result result, void *ctx) {
|
|
161
|
+
auto deferredContext = static_cast<ExtDeferredContext *>(ctx);
|
|
162
|
+
auto deferred = deferredContext->deferred;
|
|
163
|
+
delete deferredContext;
|
|
164
|
+
|
|
165
|
+
if (result != pulsar_result_Ok) {
|
|
166
|
+
deferred->Reject(std::string("Failed to close producer: ") + pulsar_result_str(result));
|
|
167
|
+
} else {
|
|
168
|
+
deferred->Resolve(THREADSAFE_DEFERRED_RESOLVER(env.Null()));
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
ctx);
|
|
172
|
+
|
|
173
|
+
return deferred->Promise();
|
|
191
174
|
}
|
|
192
175
|
|
|
193
176
|
Napi::Value Producer::GetProducerName(const Napi::CallbackInfo &info) {
|
|
194
177
|
Napi::Env env = info.Env();
|
|
195
|
-
return Napi::String::New(env, pulsar_producer_get_producer_name(this->cProducer));
|
|
178
|
+
return Napi::String::New(env, pulsar_producer_get_producer_name(this->cProducer.get()));
|
|
196
179
|
}
|
|
197
180
|
|
|
198
181
|
Napi::Value Producer::GetTopic(const Napi::CallbackInfo &info) {
|
|
199
182
|
Napi::Env env = info.Env();
|
|
200
|
-
return Napi::String::New(env, pulsar_producer_get_topic(this->cProducer));
|
|
183
|
+
return Napi::String::New(env, pulsar_producer_get_topic(this->cProducer.get()));
|
|
201
184
|
}
|
|
202
185
|
|
|
203
186
|
Napi::Value Producer::IsConnected(const Napi::CallbackInfo &info) {
|
|
204
187
|
Napi::Env env = info.Env();
|
|
205
|
-
return Napi::Boolean::New(env, pulsar_producer_is_connected(this->cProducer));
|
|
188
|
+
return Napi::Boolean::New(env, pulsar_producer_is_connected(this->cProducer.get()));
|
|
206
189
|
}
|
|
207
190
|
|
|
208
|
-
Producer::~Producer() {
|
|
191
|
+
Producer::~Producer() {}
|
package/src/Producer.h
CHANGED
|
@@ -27,14 +27,14 @@
|
|
|
27
27
|
class Producer : public Napi::ObjectWrap<Producer> {
|
|
28
28
|
public:
|
|
29
29
|
static void Init(Napi::Env env, Napi::Object exports);
|
|
30
|
-
static Napi::Value NewInstance(const Napi::CallbackInfo &info, pulsar_client_t
|
|
30
|
+
static Napi::Value NewInstance(const Napi::CallbackInfo &info, std::shared_ptr<pulsar_client_t> cClient);
|
|
31
31
|
static Napi::FunctionReference constructor;
|
|
32
32
|
Producer(const Napi::CallbackInfo &info);
|
|
33
33
|
~Producer();
|
|
34
|
-
void SetCProducer(pulsar_producer_t
|
|
34
|
+
void SetCProducer(std::shared_ptr<pulsar_producer_t> cProducer);
|
|
35
35
|
|
|
36
36
|
private:
|
|
37
|
-
pulsar_producer_t
|
|
37
|
+
std::shared_ptr<pulsar_producer_t> cProducer;
|
|
38
38
|
Napi::Value Send(const Napi::CallbackInfo &info);
|
|
39
39
|
Napi::Value Flush(const Napi::CallbackInfo &info);
|
|
40
40
|
Napi::Value Close(const Napi::CallbackInfo &info);
|
package/src/ProducerConfig.cc
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
#include "SchemaInfo.h"
|
|
20
20
|
#include "ProducerConfig.h"
|
|
21
21
|
#include <map>
|
|
22
22
|
|
|
@@ -33,10 +33,12 @@ static const std::string CFG_COMPRESS_TYPE = "compressionType";
|
|
|
33
33
|
static const std::string CFG_BATCH_ENABLED = "batchingEnabled";
|
|
34
34
|
static const std::string CFG_BATCH_MAX_DELAY = "batchingMaxPublishDelayMs";
|
|
35
35
|
static const std::string CFG_BATCH_MAX_MSG = "batchingMaxMessages";
|
|
36
|
+
static const std::string CFG_SCHEMA = "schema";
|
|
36
37
|
static const std::string CFG_PROPS = "properties";
|
|
37
38
|
static const std::string CFG_PUBLIC_KEY_PATH = "publicKeyPath";
|
|
38
39
|
static const std::string CFG_ENCRYPTION_KEY = "encryptionKey";
|
|
39
40
|
static const std::string CFG_CRYPTO_FAILURE_ACTION = "cryptoFailureAction";
|
|
41
|
+
static const std::string CFG_CHUNK_ENABLED = "chunkingEnabled";
|
|
40
42
|
|
|
41
43
|
static const std::map<std::string, pulsar_partitions_routing_mode> MESSAGE_ROUTING_MODE = {
|
|
42
44
|
{"UseSinglePartition", pulsar_UseSinglePartition},
|
|
@@ -62,7 +64,8 @@ static std::map<std::string, pulsar_producer_crypto_failure_action> PRODUCER_CRY
|
|
|
62
64
|
};
|
|
63
65
|
|
|
64
66
|
ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
65
|
-
this->cProducerConfig =
|
|
67
|
+
this->cProducerConfig = std::shared_ptr<pulsar_producer_configuration_t>(
|
|
68
|
+
pulsar_producer_configuration_create(), pulsar_producer_configuration_free);
|
|
66
69
|
|
|
67
70
|
if (producerConfig.Has(CFG_TOPIC) && producerConfig.Get(CFG_TOPIC).IsString()) {
|
|
68
71
|
this->topic = producerConfig.Get(CFG_TOPIC).ToString().Utf8Value();
|
|
@@ -71,25 +74,25 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
71
74
|
if (producerConfig.Has(CFG_PRODUCER_NAME) && producerConfig.Get(CFG_PRODUCER_NAME).IsString()) {
|
|
72
75
|
std::string producerName = producerConfig.Get(CFG_PRODUCER_NAME).ToString().Utf8Value();
|
|
73
76
|
if (!producerName.empty())
|
|
74
|
-
pulsar_producer_configuration_set_producer_name(this->cProducerConfig, producerName.c_str());
|
|
77
|
+
pulsar_producer_configuration_set_producer_name(this->cProducerConfig.get(), producerName.c_str());
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
if (producerConfig.Has(CFG_SEND_TIMEOUT) && producerConfig.Get(CFG_SEND_TIMEOUT).IsNumber()) {
|
|
78
81
|
int32_t sendTimeoutMs = producerConfig.Get(CFG_SEND_TIMEOUT).ToNumber().Int32Value();
|
|
79
82
|
if (sendTimeoutMs > 0) {
|
|
80
|
-
pulsar_producer_configuration_set_send_timeout(this->cProducerConfig, sendTimeoutMs);
|
|
83
|
+
pulsar_producer_configuration_set_send_timeout(this->cProducerConfig.get(), sendTimeoutMs);
|
|
81
84
|
}
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
if (producerConfig.Has(CFG_INIT_SEQUENCE_ID) && producerConfig.Get(CFG_INIT_SEQUENCE_ID).IsNumber()) {
|
|
85
88
|
int64_t initialSequenceId = producerConfig.Get(CFG_INIT_SEQUENCE_ID).ToNumber().Int64Value();
|
|
86
|
-
pulsar_producer_configuration_set_initial_sequence_id(this->cProducerConfig, initialSequenceId);
|
|
89
|
+
pulsar_producer_configuration_set_initial_sequence_id(this->cProducerConfig.get(), initialSequenceId);
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
if (producerConfig.Has(CFG_MAX_PENDING) && producerConfig.Get(CFG_MAX_PENDING).IsNumber()) {
|
|
90
93
|
int32_t maxPendingMessages = producerConfig.Get(CFG_MAX_PENDING).ToNumber().Int32Value();
|
|
91
94
|
if (maxPendingMessages > 0) {
|
|
92
|
-
pulsar_producer_configuration_set_max_pending_messages(this->cProducerConfig, maxPendingMessages);
|
|
95
|
+
pulsar_producer_configuration_set_max_pending_messages(this->cProducerConfig.get(), maxPendingMessages);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -98,47 +101,47 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
98
101
|
int32_t maxPendingMessagesAcrossPartitions =
|
|
99
102
|
producerConfig.Get(CFG_MAX_PENDING_ACROSS_PARTITIONS).ToNumber().Int32Value();
|
|
100
103
|
if (maxPendingMessagesAcrossPartitions > 0) {
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
pulsar_producer_configuration_set_max_pending_messages_across_partitions(
|
|
105
|
+
this->cProducerConfig.get(), maxPendingMessagesAcrossPartitions);
|
|
103
106
|
}
|
|
104
107
|
}
|
|
105
108
|
|
|
106
109
|
if (producerConfig.Has(CFG_BLOCK_IF_QUEUE_FULL) &&
|
|
107
110
|
producerConfig.Get(CFG_BLOCK_IF_QUEUE_FULL).IsBoolean()) {
|
|
108
111
|
bool blockIfQueueFull = producerConfig.Get(CFG_BLOCK_IF_QUEUE_FULL).ToBoolean().Value();
|
|
109
|
-
pulsar_producer_configuration_set_block_if_queue_full(this->cProducerConfig, blockIfQueueFull);
|
|
112
|
+
pulsar_producer_configuration_set_block_if_queue_full(this->cProducerConfig.get(), blockIfQueueFull);
|
|
110
113
|
}
|
|
111
114
|
|
|
112
115
|
if (producerConfig.Has(CFG_ROUTING_MODE) && producerConfig.Get(CFG_ROUTING_MODE).IsString()) {
|
|
113
116
|
std::string messageRoutingMode = producerConfig.Get(CFG_ROUTING_MODE).ToString().Utf8Value();
|
|
114
117
|
if (MESSAGE_ROUTING_MODE.count(messageRoutingMode))
|
|
115
|
-
pulsar_producer_configuration_set_partitions_routing_mode(this->cProducerConfig,
|
|
118
|
+
pulsar_producer_configuration_set_partitions_routing_mode(this->cProducerConfig.get(),
|
|
116
119
|
MESSAGE_ROUTING_MODE.at(messageRoutingMode));
|
|
117
120
|
}
|
|
118
121
|
|
|
119
122
|
if (producerConfig.Has(CFG_HASH_SCHEME) && producerConfig.Get(CFG_HASH_SCHEME).IsString()) {
|
|
120
123
|
std::string hashingScheme = producerConfig.Get(CFG_HASH_SCHEME).ToString().Utf8Value();
|
|
121
124
|
if (HASHING_SCHEME.count(hashingScheme))
|
|
122
|
-
pulsar_producer_configuration_set_hashing_scheme(this->cProducerConfig,
|
|
125
|
+
pulsar_producer_configuration_set_hashing_scheme(this->cProducerConfig.get(),
|
|
123
126
|
HASHING_SCHEME.at(hashingScheme));
|
|
124
127
|
}
|
|
125
128
|
|
|
126
129
|
if (producerConfig.Has(CFG_COMPRESS_TYPE) && producerConfig.Get(CFG_COMPRESS_TYPE).IsString()) {
|
|
127
130
|
std::string compressionType = producerConfig.Get(CFG_COMPRESS_TYPE).ToString().Utf8Value();
|
|
128
131
|
if (COMPRESSION_TYPE.count(compressionType))
|
|
129
|
-
pulsar_producer_configuration_set_compression_type(this->cProducerConfig,
|
|
132
|
+
pulsar_producer_configuration_set_compression_type(this->cProducerConfig.get(),
|
|
130
133
|
COMPRESSION_TYPE.at(compressionType));
|
|
131
134
|
}
|
|
132
135
|
|
|
133
136
|
if (producerConfig.Has(CFG_BATCH_ENABLED) && producerConfig.Get(CFG_BATCH_ENABLED).IsBoolean()) {
|
|
134
137
|
bool batchingEnabled = producerConfig.Get(CFG_BATCH_ENABLED).ToBoolean().Value();
|
|
135
|
-
pulsar_producer_configuration_set_batching_enabled(this->cProducerConfig, batchingEnabled);
|
|
138
|
+
pulsar_producer_configuration_set_batching_enabled(this->cProducerConfig.get(), batchingEnabled);
|
|
136
139
|
}
|
|
137
140
|
|
|
138
141
|
if (producerConfig.Has(CFG_BATCH_MAX_DELAY) && producerConfig.Get(CFG_BATCH_MAX_DELAY).IsNumber()) {
|
|
139
142
|
int64_t batchingMaxPublishDelayMs = producerConfig.Get(CFG_BATCH_MAX_DELAY).ToNumber().Int64Value();
|
|
140
143
|
if (batchingMaxPublishDelayMs > 0) {
|
|
141
|
-
pulsar_producer_configuration_set_batching_max_publish_delay_ms(this->cProducerConfig,
|
|
144
|
+
pulsar_producer_configuration_set_batching_max_publish_delay_ms(this->cProducerConfig.get(),
|
|
142
145
|
(long)batchingMaxPublishDelayMs);
|
|
143
146
|
}
|
|
144
147
|
}
|
|
@@ -146,10 +149,17 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
146
149
|
if (producerConfig.Has(CFG_BATCH_MAX_MSG) && producerConfig.Get(CFG_BATCH_MAX_MSG).IsNumber()) {
|
|
147
150
|
uint32_t batchingMaxMessages = producerConfig.Get(CFG_BATCH_MAX_MSG).ToNumber().Uint32Value();
|
|
148
151
|
if (batchingMaxMessages > 0) {
|
|
149
|
-
pulsar_producer_configuration_set_batching_max_messages(this->cProducerConfig,
|
|
152
|
+
pulsar_producer_configuration_set_batching_max_messages(this->cProducerConfig.get(),
|
|
153
|
+
batchingMaxMessages);
|
|
150
154
|
}
|
|
151
155
|
}
|
|
152
156
|
|
|
157
|
+
if (producerConfig.Has(CFG_SCHEMA) && producerConfig.Get(CFG_SCHEMA).IsObject()) {
|
|
158
|
+
SchemaInfo* schemaInfo = new SchemaInfo(producerConfig.Get(CFG_SCHEMA).ToObject());
|
|
159
|
+
schemaInfo->SetProducerSchema(this->cProducerConfig);
|
|
160
|
+
delete schemaInfo;
|
|
161
|
+
}
|
|
162
|
+
|
|
153
163
|
if (producerConfig.Has(CFG_PROPS) && producerConfig.Get(CFG_PROPS).IsObject()) {
|
|
154
164
|
Napi::Object propObj = producerConfig.Get(CFG_PROPS).ToObject();
|
|
155
165
|
Napi::Array arr = propObj.GetPropertyNames();
|
|
@@ -157,7 +167,7 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
157
167
|
for (int i = 0; i < size; i++) {
|
|
158
168
|
Napi::String key = arr.Get(i).ToString();
|
|
159
169
|
Napi::String value = propObj.Get(key).ToString();
|
|
160
|
-
pulsar_producer_configuration_set_property(this->cProducerConfig, key.Utf8Value().c_str(),
|
|
170
|
+
pulsar_producer_configuration_set_property(this->cProducerConfig.get(), key.Utf8Value().c_str(),
|
|
161
171
|
value.Utf8Value().c_str());
|
|
162
172
|
}
|
|
163
173
|
}
|
|
@@ -165,24 +175,31 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
165
175
|
if (producerConfig.Has(CFG_PUBLIC_KEY_PATH) && producerConfig.Get(CFG_PUBLIC_KEY_PATH).IsString()) {
|
|
166
176
|
std::string publicKeyPath = producerConfig.Get(CFG_PUBLIC_KEY_PATH).ToString().Utf8Value();
|
|
167
177
|
std::string privateKeyPath = "";
|
|
168
|
-
pulsar_producer_configuration_set_default_crypto_key_reader(
|
|
169
|
-
|
|
178
|
+
pulsar_producer_configuration_set_default_crypto_key_reader(
|
|
179
|
+
this->cProducerConfig.get(), publicKeyPath.c_str(), privateKeyPath.c_str());
|
|
170
180
|
if (producerConfig.Has(CFG_ENCRYPTION_KEY) && producerConfig.Get(CFG_ENCRYPTION_KEY).IsString()) {
|
|
171
181
|
std::string encryptionKey = producerConfig.Get(CFG_ENCRYPTION_KEY).ToString().Utf8Value();
|
|
172
|
-
pulsar_producer_configuration_set_encryption_key(this->cProducerConfig, encryptionKey.c_str());
|
|
182
|
+
pulsar_producer_configuration_set_encryption_key(this->cProducerConfig.get(), encryptionKey.c_str());
|
|
173
183
|
}
|
|
174
184
|
if (producerConfig.Has(CFG_CRYPTO_FAILURE_ACTION) &&
|
|
175
185
|
producerConfig.Get(CFG_CRYPTO_FAILURE_ACTION).IsString()) {
|
|
176
186
|
std::string cryptoFailureAction = producerConfig.Get(CFG_CRYPTO_FAILURE_ACTION).ToString().Utf8Value();
|
|
177
187
|
if (PRODUCER_CRYPTO_FAILURE_ACTION.count(cryptoFailureAction))
|
|
178
188
|
pulsar_producer_configuration_set_crypto_failure_action(
|
|
179
|
-
this->cProducerConfig, PRODUCER_CRYPTO_FAILURE_ACTION.at(cryptoFailureAction));
|
|
189
|
+
this->cProducerConfig.get(), PRODUCER_CRYPTO_FAILURE_ACTION.at(cryptoFailureAction));
|
|
180
190
|
}
|
|
181
191
|
}
|
|
192
|
+
|
|
193
|
+
if (producerConfig.Has(CFG_CHUNK_ENABLED) && producerConfig.Get(CFG_CHUNK_ENABLED).IsBoolean()) {
|
|
194
|
+
bool chunkingEnabled = producerConfig.Get(CFG_CHUNK_ENABLED).ToBoolean().Value();
|
|
195
|
+
pulsar_producer_configuration_set_chunking_enabled(this->cProducerConfig.get(), chunkingEnabled);
|
|
196
|
+
}
|
|
182
197
|
}
|
|
183
198
|
|
|
184
|
-
ProducerConfig::~ProducerConfig() {
|
|
199
|
+
ProducerConfig::~ProducerConfig() {}
|
|
185
200
|
|
|
186
|
-
pulsar_producer_configuration_t
|
|
201
|
+
std::shared_ptr<pulsar_producer_configuration_t> ProducerConfig::GetCProducerConfig() {
|
|
202
|
+
return this->cProducerConfig;
|
|
203
|
+
}
|
|
187
204
|
|
|
188
205
|
std::string ProducerConfig::GetTopic() { return this->topic; }
|
package/src/ProducerConfig.h
CHANGED
|
@@ -27,11 +27,11 @@ class ProducerConfig {
|
|
|
27
27
|
public:
|
|
28
28
|
ProducerConfig(const Napi::Object &producerConfig);
|
|
29
29
|
~ProducerConfig();
|
|
30
|
-
pulsar_producer_configuration_t
|
|
30
|
+
std::shared_ptr<pulsar_producer_configuration_t> GetCProducerConfig();
|
|
31
31
|
std::string GetTopic();
|
|
32
32
|
|
|
33
33
|
private:
|
|
34
|
-
pulsar_producer_configuration_t
|
|
34
|
+
std::shared_ptr<pulsar_producer_configuration_t> cProducerConfig;
|
|
35
35
|
std::string topic;
|
|
36
36
|
};
|
|
37
37
|
|