skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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,
        },
      },
    ]),
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search