Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why the service of grpc is undefined when i set configuration for kafka?

i’m trying to implement microservices with grpc and kafka but when i add both options in main.ts the client of grpc doesn’t load on "onModuleInit" method
this is my main.ts:

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.connectMicroservice<MicroserviceOptions>({
    transport: Transport.GRPC,
    options:{
      url: '0.0.0.0.:50053',
      package: protobufPackage,
      protoPath: join('./order.proto',)
    },
  });

  app.connectMicroservice<MicroserviceOptions>({
    transport: Transport.KAFKA,
    options:{
      client: {
        brokers: ['localhost:29092'],
      },
      consumer: {
        groupId: 'orders-consumer',
      },
    },
  });

  await app.startAllMicroservices();
}

and my client in the provider:

public onModuleInit(): void {
  this.service = this.clientService<ProductService>(PRODUCT_SERVICE_NAME);
}

At this point this.service is undefined only when set kafka configuration, i don’t know if I’m missing something or did I misconfigure?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any suggestion would be very helpful!

>Solution :

call await app.init() after app.startAllMicroservices()

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading