tulios / kafkajs

A modern Apache Kafka client for node.js
https://kafka.js.org
MIT License
3.75k stars 527 forks source link

[Question] How do I subscribe to future topics using a pattern? #1685

Closed dulguun0225 closed 6 months ago

dulguun0225 commented 6 months ago

I'm subscribing to topics like this:

const consumer = kafka.consumer({
  groupId: 'consumergroup0',
  allowAutoTopicCreation: true,
  metadataMaxAge: 10_000,
});

const run = async () => {
  await consumer.connect();
  console.log('consumer connected');
  await consumer.subscribe({
    topic: /mongo\.somedb.*?\.bbb/,
    fromBeginning: true,
  });
// ...
}

Let's say topics mongo.somedb_0.bbb mongo.somedb_1.bbb existed before consumer.subscribe is called. It can consume message on mongo.somedb_0.bbb mongo.somedb_1.bbb, but not any other topic that's created and matches the regex after subscribe is called. What option am I missing?