Reputation: 121
Help needed, I have created one API gateway and customer microservice written in Nest JS. In Addition, I've written Dockerfile and cloudbuild.yaml each to deploy to Cloud Run by using Cloud Build.
Everything works fine in the localhost, but not in the Cloud Run environment
While I can successfully access the API Gateway using the Cloud Run URL, calls made from the API Gateway to the Customer Microservice APIs consistently fail. Cloud Run returns a "getaddrinfo ENOTFOUND" error for these calls
Error: getaddrinfo ENOTFOUND https://mykadun-customer-service-staging-srqb3kpyjq-as.a.run.app
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:108:26)
I've checked the customer service is up and running but it cannot be access by the api gateway,
Please note that I am using TCP in Nest JS, and below is my code for api gateway and customer service:
Api Gateway
import { Module } from '@nestjs/common';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { ConfigModule, ConfigService } from '@nestjs/config';
@Module({
imports: [
ClientsModule.registerAsync([
{
name: 'CUSTOMER',
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => ({
name: configService.get('CUSTOMER_SERVICE'),
transport: Transport.TCP,
options: {
name: configService.get('CUSTOMER_SERVICE'),
host: configService.get('CUSTOMER_SERVICE_URL'),
port: Number(configService.get('CUSTOMER_SERVICE_PORT') || 8080),
},
}),
inject: [ConfigService],
},
])
],
controllers: [CustomerController],
providers: [CustomerListener, CustomerService],
})
export class CustomerModule {}
Customer Service
// nest js
import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.createMicroservice<MicroserviceOptions>(
AppModule,
{
transport: Transport.TCP,
options: {
host: '::',
port: Number(process.env.PORT || 8080)
}
},
);
await app.listen()
}
bootstrap();
Please note that I have to use '::' in my deployment to cloud run, else it just cannot be deployed
Edit: I also use '0.0.0.0' in my deployment to cloud run, it can be deploy but the result is the same, as I still cannot call the customer service from API gateway
Your help is appreciated! as I have stuck in this problem for many days
Upvotes: 0
Views: 269