Deploy of microservices gRPC using NestJS

ecadevops1PRO

a year ago

Currently I have two services running on a project. The first one is the API Gateway an the other is a microservice. Both are deployed an running but when I try use an API I got an error.ERROR [ExceptionsHandler] 14 UNAVAILABLE: No connection established

Jun 14 19:01:36

Error: 14 UNAVAILABLE: No connection establishedMy configuration of API Gateway is:

    ClientsModule.register([
      {
        name: AUTH_SERVICE,
        transport: Transport.GRPC,
        options: {
          package: AUTH_PACKAGE_NAME,
          protoPath: join(__dirname, '../auth.proto'),
        },
      },
    ]),

And is running on the port 3000

Configuration of Microservice is this

  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AuthModule,
    {
      transport: Transport.GRPC,
      options: {
        url: process.env.URL_CONFIGURATION,
        protoPath: join(__dirname, '../auth.proto'),
        package: AUTH_PACKAGE_NAME,
      },
    },
  );

Do you know what I am missing?

Thank you in advance!

16 Replies

a year ago

What do you have URL_CONFIGURATION set to?


ecadevops1PRO

a year ago

On my URL configuration I have in my local this:

URL_CONFIGURATION=0.0.0.0:3000

I don't know if it's works yet, because if I remove the URL_CONFIGURATIONstill works. Just to add I have this two services running

Attachments


a year ago

You would need to use the private domain to connect one service to another.


ecadevops1PRO

a year ago

So my configuration would be in this way:API Gateway configuration:

    ClientsModule.register([
      {
        name: AUTH_SERVICE,
        transport: Transport.GRPC,
        options: {
          url: process.env.PRIVATE_DOMAIN_API_GATEWAY,
          package: AUTH_PACKAGE_NAME,
          protoPath: join(__dirname, '../auth.proto'),
        },
      },
    ]),

Auth Microservice:

  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AuthModule,
    {
      transport: Transport.GRPC,
      options: {
        url: process.env.PRIVATE_DOMAIN_API_GATEWAY,
        protoPath: join(__dirname, '../auth.proto'),
        package: AUTH_PACKAGE_NAME,
      },
    },
  );

This configuration is ok? Or I need to change something?


a year ago

You would need to use each others private domain, in that configuration you are using the services own private domain.


ecadevops1PRO

a year ago

Oh ok. So the configuration would be this:API Gateway configuration:

    ClientsModule.register([
      {
        name: AUTH_SERVICE,
        transport: Transport.GRPC,
        options: {
          url: process.env.PRIVATE_DOMAIN_AUTH_MICROSERVICE,
          package: AUTH_PACKAGE_NAME,
          protoPath: join(__dirname, '../auth.proto'),
        },
      },
    ]),

Auth Microservice (remains the same, just to make me sure haha):

  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AuthModule,
    {
      transport: Transport.GRPC,
      options: {
        url: process.env.PRIVATE_DOMAIN_API_GATEWAY,
        protoPath: join(__dirname, '../auth.proto'),
        package: AUTH_PACKAGE_NAME,
      },
    },
  );

Thank you for your quick responses!


a year ago

What do you have those two variables set to?


ecadevops1PRO

a year ago

I have configurated this variables on both this servicesPRIVATE_DOMAIN_API_GATEWAY = grpc-nestjs.railway.internalPRIVATE_DOMAIN_AUTH_MICROSERVICE = grpc-micro.railway.internal

I tried this changes but didn't work yet


a year ago

They're URLs, so I would assume you need a port and maybe a scheme.


ecadevops1PRO

a year ago

I should generate public URLs and use them in the enviorment variables?


a year ago

No, you should be using the private network, the URLs are missing ports as I've mentioned.


ecadevops1PRO

a year ago

How do I know the port of the services?In my ApiGateway I set the port but in the microservice don't.I see the provided variables and don't see the port.

Attachments


a year ago

I'm not sure where the confusion is coming from, you mentioned a port in your original post, the port you need to use would be the port you have the other service running on.


ecadevops1PRO

a year ago

Oh ok.I got confused because I assume that the port that you refer it was on my microservice.So my code of my microservice is this:

  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AuthModule,
    {
      transport: Transport.GRPC,
      options: {
        url: `${process.env.PRIVATE_DOMAIN_API_GATEWAY}:${process.env.PORT}`,
        protoPath: join(__dirname, '../auth.proto'),
        package: AUTH_PACKAGE_NAME,
      },
    },
  );

Or maybe we can connect on Discord?


a year ago

You need to use the port that the API gateway runs on, this is a URL after all and your trying to connect your microservice to the API gateway.


ecadevops1PRO

a year ago

I made this change on my microservice:

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AuthModule,
    {
      transport: Transport.GRPC,
      options: {
        url: `${process.env.PRIVATE_DOMAIN_API_GATEWAY}:${process.env.PORT}`,
        protoPath: join(__dirname, '../auth.proto'),
        package: AUTH_PACKAGE_NAME,
      },
    },
  );
  await app.listen();
}

And my enviorments variables I configured this (image 1)And I got an error (image 2)What should I do?

Attachments


Deploy of microservices gRPC using NestJS - Railway Help Station