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?
Any suggestion would be very helpful!
CodePudding user response:
call await app.init()
after app.startAllMicroservices()