0

We have our kafka consumer application where we have one consumer group and it gets connected to multiple topics using kafkajs node js library

const consumeMessages = async() = > {
  const consumer =
      kafka.consumer({groupId : 'test-group'})
          await consumer.connect() await consumer
              .subscribe({topic : 'test-topic', fromBeginning : true})
                  await consumer.run({
                    eachMessage : async({topic, partition, message}) =
                        > {console.log({
                            value : message.value.toString(),
                          })},
                  })
}

We want to change this approach where we want to have one consumer group for one topic . like if we have 5 topics we will have 5 consumer groups . In this case how to connect to multiple group Ids?

If I do it like this:

const consumer =
    kafka.consumer({groupId : 'test-group'}, {groupId : 'test-group1'},
                   {groupId : 'test-group2'})

It's not connecting and throwing errors , cannot connect to the broker. Any idea how to achieve this?

learningmode
  • 137
  • 1
  • 10
  • can you clarify if by `consumer group` you mean one consumer? And if you want separate instance of consumer then just create the consumers separately, why would you want to put different group ids in one consumer? – Kaneki21 Jul 14 '23 at 19:26
  • correct.. i want to create a 5 different consumers with different group ids..Is there any best way to create it – learningmode Jul 14 '23 at 19:40
  • then you just have to follow the docs for creating consumers. – Kaneki21 Jul 14 '23 at 19:50

0 Answers0