1

as the title suggest. Is there a possibility to use the admin client functions from KafkaJS trough the nestJS module? I'am trying to have a more detailed grip on the creation of topics trough the API.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Esteday
  • 41
  • 3
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Feb 26 '22 at 18:28

1 Answers1

0

Create admin client and access to the topic list in onModuleInit :

async onModuleInit() {
    const kafka = new Kafka({
      clientId: 'my-app',
      brokers: ['localhost:9092'],
    });
    this.admin = kafka.admin();

    // get list of topics
    const topics = await this.admin.listTopics();

   // or create new topic
    await this.admin.createTopics({
        topics: [{
            topic: 'sample-topic',
            numPartitions: 1,
            replicationFactor: 1,
        }],
    });
 }

You can create a service for admin client and inject it in every module you want.

Mohsen Mahoski
  • 452
  • 1
  • 5
  • 14