Skip to content

Conversation

@hilleer
Copy link

@hilleer hilleer commented Feb 28, 2025

What

Accordingly to the producer standard API documentation there are event listener methods available on the Producer instance but those are not currently listed in the typings, making it difficult to find programmatically as well as showing typescript type errors: Property 'on' does not exist on type 'Producer'.ts(2339):

Screenshot 2025-02-28 at 13 02 55

From the docs:

Screenshot 2025-02-28 at 13 02 20
Screenshot 2025-02-28 at 13 02 24

This pull-request adds type definitions for the on event emitter for the event names ready and event.error described in the documentation. There might be more events available?

Checklist

  • Contains customer facing changes? Including API/behavior changes
  • Did you add sufficient unit test and/or integration test coverage for this PR?
    • If not, please explain why it is not required

Test & Review

Open questions / Follow-ups

  • Are there any more event names to be listed?

@hilleer hilleer requested review from a team as code owners February 28, 2025 12:00
@hilleer hilleer changed the title chore: list producer on event methods [Typescript] chore: list producer on event methods Feb 28, 2025
@hilleer hilleer changed the title [Typescript] chore: list producer on event methods [Typescript] chore: list producer "on" event methods by event name Feb 28, 2025
Revert formatting change
@milindl
Copy link
Contributor

milindl commented Mar 3, 2025

Hey @hilleer , the 'on' methods aren't supported on the promisified producer (which is typed in kafkajs.d.ts). The documentation you've attached is from the "Callback-Based API" section, which is typed in rdkafka.d.ts, where there are typings for the events and Producer indirectly extends EventEmitter.

@hilleer
Copy link
Author

hilleer commented Mar 3, 2025

Hey @hilleer , the 'on' methods aren't supported on the promisified producer (which is typed in kafkajs.d.ts). The documentation you've attached is from the "Callback-Based API" section, which is typed in rdkafka.d.ts, where there are typings for the events and Producer indirectly extends EventEmitter.

So we are considering the promisified API to work fully in sequential order and have no need for event listeners here?

@milindl
Copy link
Contributor

milindl commented Mar 5, 2025

Right, we're attempting to do that. For instance, if you await producer.connect(), it's actually internally using the same 'ready' event, so the waiting ends only when the producer is ready. Similarly, awaited methods throw/reject if there's an error.

There are some exceptions at the moment, for instance, for the consumer rebalances, you need to use a rebalance callback within the config. But, for the most part, you should be able to use the API in sequential order.

@hilleer hilleer closed this Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants