In our environment we'd like to loop and wait until Kafka is ready.
With KafkaJS we can simply do something like
while (true) {
try {
await admin.connect();
break;
} catch (err) {
// check if this is just saying Kafka is not connectable yet
// if so continue otherwise rethrow
}
}
In confluent-kafka-javascript the actual code being run at .connect() is a no-op, see
|
AdminClient.prototype.connect = function () { |
|
if (!this._hasUnderlyingClient) { |
|
this._client.configureCallbacks(true, this._cb_configs); |
|
LibrdKafkaError.wrap(this._client.connect(), true); |
|
} |
|
// While this could be a no-op for an existing client, we still emit the event |
|
// to have a consistent API. |
|
this._isConnected = true; |
|
this.emit('ready', { name: this._client.name() }); |
|
}; |
- so this continues through and we have to instead do some admin action like list-topics and catch errors from there.
It's not a very intuitive API and I was only able to discover through through source code diving and then confirming on line 184 of admin.js:
"Unlike the other confluent-kafka-javascript classes, this class does not ensure that it is connected to the upstream broker."
I'm opening this issue to also help others looking for help with diagnosing this problem.
Thanks.
In our environment we'd like to loop and wait until Kafka is ready.
With KafkaJS we can simply do something like
In confluent-kafka-javascript the actual code being run at
.connect()is a no-op, seeconfluent-kafka-javascript/lib/admin.js
Lines 227 to 236 in 3ae9609
It's not a very intuitive API and I was only able to discover through through source code diving and then confirming on line 184 of admin.js:
"Unlike the other confluent-kafka-javascript classes, this class does not ensure that it is connected to the upstream broker."
I'm opening this issue to also help others looking for help with diagnosing this problem.
Thanks.