Skip to content

Commit 81ab43d

Browse files
authored
[feat] Add listenerName to client config (#375)
* Allow passing listenerName to client config * Add listener to test conf, e2e test
1 parent f0f16f4 commit 81ab43d

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface ClientConfig {
3030
tlsValidateHostname?: boolean;
3131
tlsAllowInsecureConnection?: boolean;
3232
statsIntervalInSeconds?: number;
33+
listenerName?: string;
3334
log?: (level: LogLevel, file: string, line: number, message: string) => void;
3435
}
3536

src/Client.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static const std::string CFG_TLS_VALIDATE_HOSTNAME = "tlsValidateHostname";
4040
static const std::string CFG_TLS_ALLOW_INSECURE = "tlsAllowInsecureConnection";
4141
static const std::string CFG_STATS_INTERVAL = "statsIntervalInSeconds";
4242
static const std::string CFG_LOG = "log";
43+
static const std::string CFG_LISTENER_NAME = "listenerName";
4344

4445
LogCallback *Client::logCallback = nullptr;
4546

@@ -186,6 +187,11 @@ Client::Client(const Napi::CallbackInfo &info) : Napi::ObjectWrap<Client>(info)
186187
pulsar_client_configuration_set_stats_interval_in_seconds(cClientConfig.get(), statsIntervalInSeconds);
187188
}
188189

190+
if (clientConfig.Has(CFG_LISTENER_NAME) && clientConfig.Get(CFG_LISTENER_NAME).IsString()) {
191+
Napi::String listenerName = clientConfig.Get(CFG_LISTENER_NAME).ToString();
192+
pulsar_client_configuration_set_listener_name(cClientConfig.get(), listenerName.Utf8Value().c_str());
193+
}
194+
189195
try {
190196
this->cClient = std::shared_ptr<pulsar_client_t>(
191197
pulsar_client_create(serviceUrl.Utf8Value().c_str(), cClientConfig.get()), pulsar_client_free);

tests/conf/standalone.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ bindAddress=0.0.0.0
3838
# Hostname or IP address the service advertises to the outside world. If not set, the value of InetAddress.getLocalHost().getHostName() is used.
3939
advertisedAddress=localhost
4040

41+
# Used to specify multiple advertised listeners for the broker.
42+
# The value must format as <listener_name>:pulsar://<host>:<port>,
43+
# multiple listeners should separate with commas.
44+
# Do not use this configuration with advertisedAddress and brokerServicePort.
45+
# The Default value is absent means use advertisedAddress and brokerServicePort.
46+
advertisedListeners=localhost6650:pulsar://localhost:6650,localhost6651:pulsar+ssl://localhost:6651,localhost8443:pulsar+ssl://localhost:8443
47+
4148
# Name of the cluster to which this broker belongs to
4249
clusterName=standalone
4350

tests/end_to_end.test.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ const Pulsar = require('../index');
2323
(() => {
2424
describe('End To End', () => {
2525
test.each([
26-
['pulsar://localhost:6650'],
27-
['pulsar+ssl://localhost:6651'],
28-
['http://localhost:8080'],
29-
['https://localhost:8443'],
30-
])('Produce/Consume to %s', async (serviceUrl) => {
26+
{ serviceUrl: 'pulsar://localhost:6650', listenerName: undefined },
27+
{ serviceUrl: 'pulsar+ssl://localhost:6651', listenerName: 'localhost6651' },
28+
{ serviceUrl: 'http://localhost:8080', listenerName: undefined },
29+
{ serviceUrl: 'https://localhost:8443', listenerName: 'localhost8443' },
30+
])('Produce/Consume to $serviceUrl', async ({ serviceUrl, listenerName }) => {
3131
const client = new Pulsar.Client({
3232
serviceUrl,
3333
tlsTrustCertsFilePath: `${__dirname}/certificate/server.crt`,
3434
operationTimeoutSeconds: 30,
35+
listenerName,
3536
});
3637

3738
const topic = 'persistent://public/default/produce-consume';

0 commit comments

Comments
 (0)