SOHU-Co/kafka-node

Properly catch producer's ready event

davc0n opened this issue · 0 comments

Hello,

Looks like that currently a producer's ready event is not catched using the built-in method:

on (eventName: 'ready', cb: () => any): this;

Probably fcc8aef fixes the issue, but it's not included in v5.0.0 (as of today the latest version available with npm).

That's a typescript code snippet which allows to properly wait until a producer (which type is kafka.Producer) is ready:

const onReady = () => {
    if ((producer as any).client.ready) {
        // ...
    }
    else setTimeout(onReady, 1000);
}

onReady();