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

How to consume messages from multiple topics #1672

Open
Torchu opened this issue Mar 27, 2024 · 1 comment
Open

How to consume messages from multiple topics #1672

Torchu opened this issue Mar 27, 2024 · 1 comment

Comments

@Torchu
Copy link

Torchu commented Mar 27, 2024

I'm consuming messages from different topics and for each subgroup of topics I want to process the messages in a different way.
Example:

const consumer = kafka.consumer({ groupId: 'my-group' });
await consumer.connect();
await consumer.subscribe({ topics: ['topic-A', 'topic-B', 'topic-C'] });
await consumer.run({
    eachMessage: async ({ topic, partition, message, heartbeat, pause }) => {
        if (topic === 'topic-A') {
            myFuncA(message);
        } else {
            myFuncB(message);
        }
    }
});

Is this the proper way to do it or should I create 2 different consuming groups: one for 'topic-A' and another one for 'topic-B' and 'topic-C' ?

@eagleeye
Copy link

yes, this is proper way how to do this. If you create multiple consumer groups - it will create 3x connections and 3x more requests to Kafka.

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