pulsar-client 1.6.2-rc.1 → 1.7.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 +50 -7
- package/binding.gyp +23 -5
- package/docker-tests.sh +4 -3
- package/index.d.ts +5 -4
- package/package.json +4 -10
- package/pulsar-test-service-start.sh +1 -1
- package/pulsar-version.txt +1 -1
- package/run-unit-tests.sh +1 -1
- package/src/Client.cc +84 -58
- package/src/Client.h +6 -4
- package/src/Consumer.cc +260 -231
- package/src/Consumer.h +9 -9
- package/src/ConsumerConfig.cc +33 -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 +33 -22
- package/src/ProducerConfig.h +2 -2
- package/src/Reader.cc +98 -129
- package/src/Reader.h +3 -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/tests/consumer.test.js +2 -2
- package/tests/end_to_end.test.js +2 -2
- package/tests/producer.test.js +2 -2
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,6 +33,7 @@ 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";
|
|
@@ -62,7 +63,8 @@ static std::map<std::string, pulsar_producer_crypto_failure_action> PRODUCER_CRY
|
|
|
62
63
|
};
|
|
63
64
|
|
|
64
65
|
ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
65
|
-
this->cProducerConfig =
|
|
66
|
+
this->cProducerConfig = std::shared_ptr<pulsar_producer_configuration_t>(
|
|
67
|
+
pulsar_producer_configuration_create(), pulsar_producer_configuration_free);
|
|
66
68
|
|
|
67
69
|
if (producerConfig.Has(CFG_TOPIC) && producerConfig.Get(CFG_TOPIC).IsString()) {
|
|
68
70
|
this->topic = producerConfig.Get(CFG_TOPIC).ToString().Utf8Value();
|
|
@@ -71,25 +73,25 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
71
73
|
if (producerConfig.Has(CFG_PRODUCER_NAME) && producerConfig.Get(CFG_PRODUCER_NAME).IsString()) {
|
|
72
74
|
std::string producerName = producerConfig.Get(CFG_PRODUCER_NAME).ToString().Utf8Value();
|
|
73
75
|
if (!producerName.empty())
|
|
74
|
-
pulsar_producer_configuration_set_producer_name(this->cProducerConfig, producerName.c_str());
|
|
76
|
+
pulsar_producer_configuration_set_producer_name(this->cProducerConfig.get(), producerName.c_str());
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
if (producerConfig.Has(CFG_SEND_TIMEOUT) && producerConfig.Get(CFG_SEND_TIMEOUT).IsNumber()) {
|
|
78
80
|
int32_t sendTimeoutMs = producerConfig.Get(CFG_SEND_TIMEOUT).ToNumber().Int32Value();
|
|
79
81
|
if (sendTimeoutMs > 0) {
|
|
80
|
-
pulsar_producer_configuration_set_send_timeout(this->cProducerConfig, sendTimeoutMs);
|
|
82
|
+
pulsar_producer_configuration_set_send_timeout(this->cProducerConfig.get(), sendTimeoutMs);
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
if (producerConfig.Has(CFG_INIT_SEQUENCE_ID) && producerConfig.Get(CFG_INIT_SEQUENCE_ID).IsNumber()) {
|
|
85
87
|
int64_t initialSequenceId = producerConfig.Get(CFG_INIT_SEQUENCE_ID).ToNumber().Int64Value();
|
|
86
|
-
pulsar_producer_configuration_set_initial_sequence_id(this->cProducerConfig, initialSequenceId);
|
|
88
|
+
pulsar_producer_configuration_set_initial_sequence_id(this->cProducerConfig.get(), initialSequenceId);
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
if (producerConfig.Has(CFG_MAX_PENDING) && producerConfig.Get(CFG_MAX_PENDING).IsNumber()) {
|
|
90
92
|
int32_t maxPendingMessages = producerConfig.Get(CFG_MAX_PENDING).ToNumber().Int32Value();
|
|
91
93
|
if (maxPendingMessages > 0) {
|
|
92
|
-
pulsar_producer_configuration_set_max_pending_messages(this->cProducerConfig, maxPendingMessages);
|
|
94
|
+
pulsar_producer_configuration_set_max_pending_messages(this->cProducerConfig.get(), maxPendingMessages);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
|
|
@@ -98,47 +100,47 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
98
100
|
int32_t maxPendingMessagesAcrossPartitions =
|
|
99
101
|
producerConfig.Get(CFG_MAX_PENDING_ACROSS_PARTITIONS).ToNumber().Int32Value();
|
|
100
102
|
if (maxPendingMessagesAcrossPartitions > 0) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
pulsar_producer_configuration_set_max_pending_messages_across_partitions(
|
|
104
|
+
this->cProducerConfig.get(), maxPendingMessagesAcrossPartitions);
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
if (producerConfig.Has(CFG_BLOCK_IF_QUEUE_FULL) &&
|
|
107
109
|
producerConfig.Get(CFG_BLOCK_IF_QUEUE_FULL).IsBoolean()) {
|
|
108
110
|
bool blockIfQueueFull = producerConfig.Get(CFG_BLOCK_IF_QUEUE_FULL).ToBoolean().Value();
|
|
109
|
-
pulsar_producer_configuration_set_block_if_queue_full(this->cProducerConfig, blockIfQueueFull);
|
|
111
|
+
pulsar_producer_configuration_set_block_if_queue_full(this->cProducerConfig.get(), blockIfQueueFull);
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
if (producerConfig.Has(CFG_ROUTING_MODE) && producerConfig.Get(CFG_ROUTING_MODE).IsString()) {
|
|
113
115
|
std::string messageRoutingMode = producerConfig.Get(CFG_ROUTING_MODE).ToString().Utf8Value();
|
|
114
116
|
if (MESSAGE_ROUTING_MODE.count(messageRoutingMode))
|
|
115
|
-
pulsar_producer_configuration_set_partitions_routing_mode(this->cProducerConfig,
|
|
117
|
+
pulsar_producer_configuration_set_partitions_routing_mode(this->cProducerConfig.get(),
|
|
116
118
|
MESSAGE_ROUTING_MODE.at(messageRoutingMode));
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
if (producerConfig.Has(CFG_HASH_SCHEME) && producerConfig.Get(CFG_HASH_SCHEME).IsString()) {
|
|
120
122
|
std::string hashingScheme = producerConfig.Get(CFG_HASH_SCHEME).ToString().Utf8Value();
|
|
121
123
|
if (HASHING_SCHEME.count(hashingScheme))
|
|
122
|
-
pulsar_producer_configuration_set_hashing_scheme(this->cProducerConfig,
|
|
124
|
+
pulsar_producer_configuration_set_hashing_scheme(this->cProducerConfig.get(),
|
|
123
125
|
HASHING_SCHEME.at(hashingScheme));
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
if (producerConfig.Has(CFG_COMPRESS_TYPE) && producerConfig.Get(CFG_COMPRESS_TYPE).IsString()) {
|
|
127
129
|
std::string compressionType = producerConfig.Get(CFG_COMPRESS_TYPE).ToString().Utf8Value();
|
|
128
130
|
if (COMPRESSION_TYPE.count(compressionType))
|
|
129
|
-
pulsar_producer_configuration_set_compression_type(this->cProducerConfig,
|
|
131
|
+
pulsar_producer_configuration_set_compression_type(this->cProducerConfig.get(),
|
|
130
132
|
COMPRESSION_TYPE.at(compressionType));
|
|
131
133
|
}
|
|
132
134
|
|
|
133
135
|
if (producerConfig.Has(CFG_BATCH_ENABLED) && producerConfig.Get(CFG_BATCH_ENABLED).IsBoolean()) {
|
|
134
136
|
bool batchingEnabled = producerConfig.Get(CFG_BATCH_ENABLED).ToBoolean().Value();
|
|
135
|
-
pulsar_producer_configuration_set_batching_enabled(this->cProducerConfig, batchingEnabled);
|
|
137
|
+
pulsar_producer_configuration_set_batching_enabled(this->cProducerConfig.get(), batchingEnabled);
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
if (producerConfig.Has(CFG_BATCH_MAX_DELAY) && producerConfig.Get(CFG_BATCH_MAX_DELAY).IsNumber()) {
|
|
139
141
|
int64_t batchingMaxPublishDelayMs = producerConfig.Get(CFG_BATCH_MAX_DELAY).ToNumber().Int64Value();
|
|
140
142
|
if (batchingMaxPublishDelayMs > 0) {
|
|
141
|
-
pulsar_producer_configuration_set_batching_max_publish_delay_ms(this->cProducerConfig,
|
|
143
|
+
pulsar_producer_configuration_set_batching_max_publish_delay_ms(this->cProducerConfig.get(),
|
|
142
144
|
(long)batchingMaxPublishDelayMs);
|
|
143
145
|
}
|
|
144
146
|
}
|
|
@@ -146,10 +148,17 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
146
148
|
if (producerConfig.Has(CFG_BATCH_MAX_MSG) && producerConfig.Get(CFG_BATCH_MAX_MSG).IsNumber()) {
|
|
147
149
|
uint32_t batchingMaxMessages = producerConfig.Get(CFG_BATCH_MAX_MSG).ToNumber().Uint32Value();
|
|
148
150
|
if (batchingMaxMessages > 0) {
|
|
149
|
-
pulsar_producer_configuration_set_batching_max_messages(this->cProducerConfig,
|
|
151
|
+
pulsar_producer_configuration_set_batching_max_messages(this->cProducerConfig.get(),
|
|
152
|
+
batchingMaxMessages);
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
|
|
156
|
+
if (producerConfig.Has(CFG_SCHEMA) && producerConfig.Get(CFG_SCHEMA).IsObject()) {
|
|
157
|
+
SchemaInfo* schemaInfo = new SchemaInfo(producerConfig.Get(CFG_SCHEMA).ToObject());
|
|
158
|
+
schemaInfo->SetProducerSchema(this->cProducerConfig);
|
|
159
|
+
delete schemaInfo;
|
|
160
|
+
}
|
|
161
|
+
|
|
153
162
|
if (producerConfig.Has(CFG_PROPS) && producerConfig.Get(CFG_PROPS).IsObject()) {
|
|
154
163
|
Napi::Object propObj = producerConfig.Get(CFG_PROPS).ToObject();
|
|
155
164
|
Napi::Array arr = propObj.GetPropertyNames();
|
|
@@ -157,7 +166,7 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
157
166
|
for (int i = 0; i < size; i++) {
|
|
158
167
|
Napi::String key = arr.Get(i).ToString();
|
|
159
168
|
Napi::String value = propObj.Get(key).ToString();
|
|
160
|
-
pulsar_producer_configuration_set_property(this->cProducerConfig, key.Utf8Value().c_str(),
|
|
169
|
+
pulsar_producer_configuration_set_property(this->cProducerConfig.get(), key.Utf8Value().c_str(),
|
|
161
170
|
value.Utf8Value().c_str());
|
|
162
171
|
}
|
|
163
172
|
}
|
|
@@ -165,24 +174,26 @@ ProducerConfig::ProducerConfig(const Napi::Object& producerConfig) : topic("") {
|
|
|
165
174
|
if (producerConfig.Has(CFG_PUBLIC_KEY_PATH) && producerConfig.Get(CFG_PUBLIC_KEY_PATH).IsString()) {
|
|
166
175
|
std::string publicKeyPath = producerConfig.Get(CFG_PUBLIC_KEY_PATH).ToString().Utf8Value();
|
|
167
176
|
std::string privateKeyPath = "";
|
|
168
|
-
pulsar_producer_configuration_set_default_crypto_key_reader(
|
|
169
|
-
|
|
177
|
+
pulsar_producer_configuration_set_default_crypto_key_reader(
|
|
178
|
+
this->cProducerConfig.get(), publicKeyPath.c_str(), privateKeyPath.c_str());
|
|
170
179
|
if (producerConfig.Has(CFG_ENCRYPTION_KEY) && producerConfig.Get(CFG_ENCRYPTION_KEY).IsString()) {
|
|
171
180
|
std::string encryptionKey = producerConfig.Get(CFG_ENCRYPTION_KEY).ToString().Utf8Value();
|
|
172
|
-
pulsar_producer_configuration_set_encryption_key(this->cProducerConfig, encryptionKey.c_str());
|
|
181
|
+
pulsar_producer_configuration_set_encryption_key(this->cProducerConfig.get(), encryptionKey.c_str());
|
|
173
182
|
}
|
|
174
183
|
if (producerConfig.Has(CFG_CRYPTO_FAILURE_ACTION) &&
|
|
175
184
|
producerConfig.Get(CFG_CRYPTO_FAILURE_ACTION).IsString()) {
|
|
176
185
|
std::string cryptoFailureAction = producerConfig.Get(CFG_CRYPTO_FAILURE_ACTION).ToString().Utf8Value();
|
|
177
186
|
if (PRODUCER_CRYPTO_FAILURE_ACTION.count(cryptoFailureAction))
|
|
178
187
|
pulsar_producer_configuration_set_crypto_failure_action(
|
|
179
|
-
this->cProducerConfig, PRODUCER_CRYPTO_FAILURE_ACTION.at(cryptoFailureAction));
|
|
188
|
+
this->cProducerConfig.get(), PRODUCER_CRYPTO_FAILURE_ACTION.at(cryptoFailureAction));
|
|
180
189
|
}
|
|
181
190
|
}
|
|
182
191
|
}
|
|
183
192
|
|
|
184
|
-
ProducerConfig::~ProducerConfig() {
|
|
193
|
+
ProducerConfig::~ProducerConfig() {}
|
|
185
194
|
|
|
186
|
-
pulsar_producer_configuration_t
|
|
195
|
+
std::shared_ptr<pulsar_producer_configuration_t> ProducerConfig::GetCProducerConfig() {
|
|
196
|
+
return this->cProducerConfig;
|
|
197
|
+
}
|
|
187
198
|
|
|
188
199
|
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
|
|