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

producer.produce should be a promise #1094

Open
fberrez opened this issue Sep 17, 2024 · 1 comment
Open

producer.produce should be a promise #1094

fberrez opened this issue Sep 17, 2024 · 1 comment

Comments

@fberrez
Copy link

fberrez commented Sep 17, 2024

Environment Information

  • node-rdkafka version: 3.1.0

Steps to Reproduce

const { Producer } = require('node-rdkafka');

async function produce() {
  const producer = new Producer({
    'client.id': 'client-id',
    'metadata.broker.list': 'localhost:9092',
  });
  await producer.connect();
  // ...wait for readiness
  producer.produce('local.ssh-sender', null, Buffer.from('Hello Kafka!'), 'key', Date.now());
  process.exit(0)
}

produce();

Additional context

This code will never send the message in the kafka queue because producer.produce is not a promise so process.exit will be executed (almost) at the same time

@aferrando-tid
Copy link

While it's true that it would be a nice to have produce returning a promise, it also accepts a callback. You can wrap the call in a new Promise and then you can await on it.

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

No branches or pull requests

2 participants