Home > database >  What should be the host name in nestjs hybrid microservice when deployed on Kubernetes
What should be the host name in nestjs hybrid microservice when deployed on Kubernetes

Time:12-26

Tech stack - nestjs - 2 microservice kubernetes - AWS EKS Ingress - nginx

Hybrid

  const app = await NestFactory.create(AppModule);
  const microservice = app.connectMicroservice<MicroserviceOptions>(
    {
      transport: Transport.TCP,
      options: {
        host: process.env.TCP_HOST,
        port: parseInt(process.env.TCP_EVALUATION_PORT),
      },
    },
    { inheritAppConfig: true },
  );
  await app.startAllMicroservices();
  await app.listen(parseInt(config.get(ConfigEnum.PORT)), '0.0.0.0');

env

  TCP_HOST: '0.0.0.0'
  TCP_CORE_PORT: 8080
  TCP_EVALUATION_PORT: 8080

Error

"connect ECONNREFUSED 0.0.0.0:8080"

Do I need to expose this port in docker or add it somewhere in the security group? Or may be need to pass a different host?

Note: App is deployed properly without any error and HTTP Rest API seems to be working fine but not the TCP @messagePattern!

Thanks

CodePudding user response:

Create a service to match the instances you want to connect to and use the service name.

CodePudding user response:

Basically in Hybrid application, main.ts configuration will be like below -

service1

  const app = await NestFactory.create(AppModule);
  const microservice = app.connectMicroservice<MicroserviceOptions>(
    {
      transport: Transport.TCP,
      options: {
        host: '0.0.0.0',
        port: 6200,
      },
    },
    { inheritAppConfig: true },
  );
  await app.startAllMicroservices();
  await app.listen(6300, '0.0.0.0');

In client

ClientsModule.register([
  {
    name: 'service1',
    transport: Transport.TCP,
    options: {
      host: 'service1',
      port: 6200,
    },
  },
]),
  • Related