Giter Club home page Giter Club logo

Comments (5)

tulios avatar tulios commented on August 20, 2024 1

You can follow issue #67

from kafkajs.

tulios avatar tulios commented on August 20, 2024

Hi @al66, you can call disconnect, it will wait for your consumers to finish the current set of messages and then disconnect. You don't need pause for that, example:

const consumers = [...]
await Promise.all(consumers)
console.log('disconnected')

from kafkajs.

al66 avatar al66 commented on August 20, 2024

Hi @tulios . That was my first try.
But with the same result.

I think the reason is, that the cluster is also disconnected in the first call.
Would it possible to add a method "stop", which doesn't disconnect the cluster directly?

  /**
   * @return {Promise}
   */
  const disconnect = async () => {
    try {
      if (runner) {
        await runner.stop()
        logger.debug('consumer has stopped, disconnecting', { groupId })
      }
      await cluster.disconnect()
    } catch (e) {}
    logger.info('Stopped', { groupId })
}

Here is my original coding:

	/**
	 * Service stopped lifecycle event handler
	 */
	async stopped() {
        
        await Promise.all(this.subscriptions.map(async (subscription) => {
            try {
                await subscription.consumer.disconnect();
                this.logger.info(`Consumer for subscription ${subscription.id} stopped`);

            } catch(err) {
                this.logger.warn(`Stopping consumer for subscription ${subscription.id} failed`);
            }
            Promise.resolve();
        }));
        this.logger.info(`All consumers disconnected`);

    }

from kafkajs.

tulios avatar tulios commented on August 20, 2024

You are right, I think we usually subscribe to different topics instead of creating several consumers. I'll create an issue to add the stop method. In the meantime you can create a new client for each consumer (new Kafka(...))

from kafkajs.

tulios avatar tulios commented on August 20, 2024

This wasn't necessary, please check issue #67 (just to document)

from kafkajs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.