Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")",
],
"defines": ["NAPI_VERSION=4"],
"defines": [
"NAPI_VERSION=4",
"PULSAR_CLIENT_NODE_VERSION=\"<!(node -e \\\"require('./package.json').version\\\")\""
],
"sources": [
"src/addon.cc",
"src/Message.cc",
Expand Down
15 changes: 11 additions & 4 deletions src/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <pulsar/c/client_configuration.h>
#include <pulsar/c/result.h>
#include "pulsar/ClientConfiguration.h"
#include <sstream>

static const std::string CFG_SERVICE_URL = "serviceUrl";
static const std::string CFG_AUTH = "authentication";
Expand Down Expand Up @@ -232,11 +233,17 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Client>(info)
pulsar_client_configuration_set_listener_name(cClientConfig.get(), listenerName.Utf8Value().c_str());
}

try {
this->cClient = std::shared_ptr<pulsar_client_t>(
pulsar_client_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free);
// Set client description to identify this as a Node.js client
// Using the Node.js client version from package.json
std::ostringstream oss;
oss << "node-client-v" << PULSAR_CLIENT_NODE_VERSION;
cClientConfig.get()->conf.setDescription(oss.str());

try {
this->cClient = std::shared_ptr<pulsar_client_t>(
pulsar_client_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free);
} catch (const std::exception &e) {
Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
Napi::Error::New(env, e.what()).ThrowAsJavaScriptException();
}
}

Expand Down
Loading