shibd commented on code in PR #357:
URL:
https://github.com/apache/pulsar-client-node/pull/357#discussion_r1444113403
##########
src/Consumer.cc:
##########
@@ -192,36 +193,17 @@ struct ConsumerNewInstanceContext {
Napi::Value Consumer::NewInstance(const Napi::CallbackInfo &info,
std::shared_ptr<pulsar_client_t> cClient) {
auto deferred = ThreadSafeDeferred::New(info.Env());
auto config = info[0].As<Napi::Object>();
- std::shared_ptr<ConsumerConfig> consumerConfig =
std::make_shared<ConsumerConfig>(config, &MessageListener);
+ std::shared_ptr<ConsumerConfig> consumerConfig =
std::make_shared<ConsumerConfig>();
+
+ consumerConfig->InitConfig(deferred, config, &MessageListener);
+ if (deferred->IsDone()) {
+ return deferred->Promise();
+ }
const std::string &topic = consumerConfig->GetTopic();
const std::vector<std::string> &topics = consumerConfig->GetTopics();
const std::string &topicsPattern = consumerConfig->GetTopicsPattern();
- if (topic.empty() && topics.size() == 0 && topicsPattern.empty()) {
- deferred->Reject(
- std::string("Topic, topics or topicsPattern is required and must be
specified as a string when "
- "creating consumer"));
- return deferred->Promise();
- }
const std::string &subscription = consumerConfig->GetSubscription();
- if (subscription.empty()) {
- deferred->Reject(
- std::string("Subscription is required and must be specified as a
string when creating consumer"));
- return deferred->Promise();
- }
- int32_t ackTimeoutMs = consumerConfig->GetAckTimeoutMs();
- if (ackTimeoutMs != 0 && ackTimeoutMs < MIN_ACK_TIMEOUT_MILLIS) {
- std::string msg("Ack timeout should be 0 or greater than or equal to " +
- std::to_string(MIN_ACK_TIMEOUT_MILLIS));
- deferred->Reject(msg);
- return deferred->Promise();
- }
- int32_t nAckRedeliverTimeoutMs = consumerConfig->GetNAckRedeliverTimeoutMs();
- if (nAckRedeliverTimeoutMs < 0) {
- std::string msg("NAck timeout should be greater than or equal to zero");
- deferred->Reject(msg);
- return deferred->Promise();
Review Comment:
Sorry for the late reply. The original code, check settings logic are
separated, which will have the following problems:
1. For Some settings, we need to call the C API to determine whether it is
successful or not, such as
https://github.com/apache/pulsar-client-node/pull/357/files#diff-ca2d7e89de2051db6eacdda40a5abc459724a390b40df60a1e54857caa2ee5f5R321-R325,
which we can't do with the original code.
2. After refactoring this way, putting the check settings in a method will
make the code clear.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]