From db33dba8d4a35692bb1617d052d62f37eb2764e7 Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Wed, 28 Jan 2026 19:41:32 +0800 Subject: [PATCH 1/2] Fix issue #3505: Set client description to identify Node.js client Add 'description' parameter to Client configuration and set default value to 'node' so that clientVersion in topic stats displays as 'Pulsar-CPP-vX.Y.Z-node' instead of just 'Pulsar-CPP-vX.Y.Z'. This allows operators to distinguish Node.js clients from C++ clients in topic statistics. Changes: - Add CFG_DESCRIPTION constant for description configuration parameter - Parse description from JavaScript client configuration - Set default description to 'node' to identify as Node.js client - Add 'description' to TypeScript ClientConfig interface - Allow users to override description if needed Fixes #3505 --- index.d.ts | 1 + src/Client.cc | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/index.d.ts b/index.d.ts index b85b623..6682b83 100644 --- a/index.d.ts +++ b/index.d.ts @@ -36,6 +36,7 @@ export interface ClientConfig { log?: (level: LogLevel, file: string, line: number, message: string) => void; logLevel?: LogLevel; connectionTimeoutMs?: number; + description?: string; } export class Client { diff --git a/src/Client.cc b/src/Client.cc index 29d542c..19f8bc0 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -46,6 +46,7 @@ static const std::string CFG_LOG = "log"; static const std::string CFG_LOG_LEVEL = "logLevel"; static const std::string CFG_LISTENER_NAME = "listenerName"; static const std::string CFG_CONNECTION_TIMEOUT = "connectionTimeoutMs"; +static const std::string CFG_DESCRIPTION = "description"; LogCallback *Client::logCallback = nullptr; @@ -232,6 +233,13 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) pulsar_client_configuration_set_listener_name(cClientConfig.get(), listenerName.Utf8Value().c_str()); } + // Set client description to identify this as the Node.js client + std::string description = "node"; + if (clientConfig.Has(CFG_DESCRIPTION) && clientConfig.Get(CFG_DESCRIPTION).IsString()) { + description = clientConfig.Get(CFG_DESCRIPTION).ToString().Utf8Value(); + } + cClientConfig.get()->conf.setDescription(description); + try { this->cClient = std::shared_ptr( pulsar_client_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free); From 1f68e4e381fadf8bcb6d99114f00aca4566c437d Mon Sep 17 00:00:00 2001 From: Baodi Shi Date: Wed, 28 Jan 2026 19:49:17 +0800 Subject: [PATCH 2/2] Fix issue #3505: Set client description to identify Node.js client Automatically set client description to 'node-client-vX.Y.Z' using the Node.js client version from package.json, so that clientVersion in topic stats displays as 'Pulsar-CPP-vX.Y.Z-node-client-vA.B.C' instead of just 'Pulsar-CPP-vX.Y.Z'. This allows operators to distinguish Node.js clients from C++ clients in topic statistics without requiring users to configure anything. Changes: - Add PULSAR_CLIENT_NODE_VERSION define in binding.gyp to read version from package.json - Set client description to 'node-client-v' in Client constructor - Remove user-configurable description parameter (not needed, automatic) - Add header for string formatting - Remove description from TypeScript ClientConfig interface Fixes #3505 --- binding.gyp | 5 ++++- index.d.ts | 1 - src/Client.cc | 21 ++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/binding.gyp b/binding.gyp index 563dce5..a738fbb 100644 --- a/binding.gyp +++ b/binding.gyp @@ -27,7 +27,10 @@ "include_dirs": [ " void; logLevel?: LogLevel; connectionTimeoutMs?: number; - description?: string; } export class Client { diff --git a/src/Client.cc b/src/Client.cc index 19f8bc0..07ca2ab 100644 --- a/src/Client.cc +++ b/src/Client.cc @@ -27,6 +27,7 @@ #include #include #include "pulsar/ClientConfiguration.h" +#include static const std::string CFG_SERVICE_URL = "serviceUrl"; static const std::string CFG_AUTH = "authentication"; @@ -46,7 +47,6 @@ static const std::string CFG_LOG = "log"; static const std::string CFG_LOG_LEVEL = "logLevel"; static const std::string CFG_LISTENER_NAME = "listenerName"; static const std::string CFG_CONNECTION_TIMEOUT = "connectionTimeoutMs"; -static const std::string CFG_DESCRIPTION = "description"; LogCallback *Client::logCallback = nullptr; @@ -233,18 +233,17 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) pulsar_client_configuration_set_listener_name(cClientConfig.get(), listenerName.Utf8Value().c_str()); } - // Set client description to identify this as the Node.js client - std::string description = "node"; - if (clientConfig.Has(CFG_DESCRIPTION) && clientConfig.Get(CFG_DESCRIPTION).IsString()) { - description = clientConfig.Get(CFG_DESCRIPTION).ToString().Utf8Value(); - } - cClientConfig.get()->conf.setDescription(description); + // 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_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free); + try { + this->cClient = std::shared_ptr( + 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(); } }