Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] Add listenerName to client config #375

Merged
Merged
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
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface ClientConfig {
tlsValidateHostname?: boolean;
tlsAllowInsecureConnection?: boolean;
statsIntervalInSeconds?: number;
listenerName?: string;
log?: (level: LogLevel, file: string, line: number, message: string) => void;
}

Expand Down
6 changes: 6 additions & 0 deletions src/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static const std::string CFG_TLS_VALIDATE_HOSTNAME = "tlsValidateHostname";
static const std::string CFG_TLS_ALLOW_INSECURE = "tlsAllowInsecureConnection";
static const std::string CFG_STATS_INTERVAL = "statsIntervalInSeconds";
static const std::string CFG_LOG = "log";
static const std::string CFG_LISTENER_NAME = "listenerName";

LogCallback *Client::logCallback = nullptr;

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

if (clientConfig.Has(CFG_LISTENER_NAME) && clientConfig.Get(CFG_LISTENER_NAME).IsString()) {
Napi::String listenerName = clientConfig.Get(CFG_LISTENER_NAME).ToString();
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);
Expand Down
7 changes: 7 additions & 0 deletions tests/conf/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ bindAddress=0.0.0.0
# Hostname or IP address the service advertises to the outside world. If not set, the value of InetAddress.getLocalHost().getHostName() is used.
advertisedAddress=localhost

# Used to specify multiple advertised listeners for the broker.
# The value must format as <listener_name>:pulsar://<host>:<port>,
# multiple listeners should separate with commas.
# Do not use this configuration with advertisedAddress and brokerServicePort.
# The Default value is absent means use advertisedAddress and brokerServicePort.
advertisedListeners=localhost6650:pulsar://localhost:6650,localhost6651:pulsar+ssl://localhost:6651,localhost8443:pulsar+ssl://localhost:8443

# Name of the cluster to which this broker belongs to
clusterName=standalone

Expand Down
11 changes: 6 additions & 5 deletions tests/end_to_end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@
(() => {
describe('End To End', () => {
test.each([
['pulsar://localhost:6650'],
['pulsar+ssl://localhost:6651'],
['http://localhost:8080'],
['https://localhost:8443'],
])('Produce/Consume to %s', async (serviceUrl) => {
{ serviceUrl: 'pulsar://localhost:6650', listenerName: undefined },
{ serviceUrl: 'pulsar+ssl://localhost:6651', listenerName: 'localhost6651' },
{ serviceUrl: 'http://localhost:8080', listenerName: undefined },
{ serviceUrl: 'https://localhost:8443', listenerName: 'localhost8443' },
])('Produce/Consume to $serviceUrl', async ({ serviceUrl, listenerName }) => {
const client = new Pulsar.Client({
serviceUrl,
tlsTrustCertsFilePath: `${__dirname}/certificate/server.crt`,
operationTimeoutSeconds: 30,
listenerName,
});

const topic = 'persistent://public/default/produce-consume';
Expand Down Expand Up @@ -309,7 +310,7 @@
});

let consumer2Recv = 0;
while (true) {

Check warning on line 313 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

Unexpected constant condition

Check warning on line 313 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

Unexpected constant condition
try {
const msg = await consumer2.receive(3000);
await new Promise((resolve) => setTimeout(resolve, 10));
Expand Down Expand Up @@ -354,7 +355,7 @@
topic,
startMessageId: Pulsar.MessageId.earliest(),
receiverQueueSize: 10,
listener: async (message, reader) => {

Check warning on line 358 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used

Check warning on line 358 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'reader' is defined but never used

Check warning on line 358 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used
await new Promise((resolve) => setTimeout(resolve, 10));
reader1Recv += 1;
},
Expand Down Expand Up @@ -386,7 +387,7 @@
await client.close();
});

test('Message Listener error handling', async () => {

Check warning on line 390 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

Test has no assertions
const client = new Pulsar.Client({
serviceUrl: 'pulsar://localhost:6650',
});
Expand Down Expand Up @@ -422,7 +423,7 @@
subscription: 'sync',
subscriptionType: 'Shared',
subscriptionInitialPosition: 'Earliest',
listener: (message, messageConsumer) => {

Check warning on line 426 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used

Check warning on line 426 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'messageConsumer' is defined but never used
throw new Error('consumer1 callback expected error');
},
});
Expand All @@ -432,7 +433,7 @@
subscription: 'async',
subscriptionType: 'Shared',
subscriptionInitialPosition: 'Earliest',
listener: async (message, messageConsumer) => {

Check warning on line 436 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'message' is defined but never used

Check warning on line 436 in tests/end_to_end.test.js

View workflow job for this annotation

GitHub Actions / Run unit tests (3.10)

'messageConsumer' is defined but never used
throw new Error('consumer2 callback expected error');
},
});
Expand Down
Loading