How to use the @nestjs/microservices.Transport.GRPC function in @nestjs/microservices

To help you get started, weโ€™ve selected a few @nestjs/microservices examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github new-eden-social / new-eden-social / src / services / notification / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(NotificationModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'notification',
      protoPath: join(__dirname, 'src/grpc/notification.proto'),
    },
  });

  app.connectMicroservice({
    transport: Transport.REDIS,
    options: {
      url: process.env.REDIS_HOST,
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
github nestjs / terminus / lib / health-indicators / microservice / grpc.health.ts View on Github external
private createClient(
    options: CheckGRPCServiceOptions,
  ): NestJSMicroservices.ClientGrpc {
    const {
      timeout,
      healthServiceName,
      healthServiceCheck,
      ...grpcOptions
    } = options;
    // TODO: Remove `as any` as soon nestjs/nest#2240 gets merged
    return this.nestJsMicroservices.ClientProxyFactory.create({
      transport: Transport.GRPC,
      options: grpcOptions as GrpcOptionsOptions,
    }) as any;
  }
github new-eden-social / new-eden-social / src / services / alliance / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(AllianceModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'alliance',
      protoPath: join(__dirname, 'src/grpc/alliance.proto'),
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
github new-eden-social / new-eden-social / src / services / follow / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(FollowModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'follow',
      protoPath: join(__dirname, 'src/grpc/follow.proto'),
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
github new-eden-social / new-eden-social / src / services / comment / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(CommentModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'post',
      protoPath: join(__dirname, 'src/grpc/post.proto'),
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
github new-eden-social / new-eden-social / src / services / hashtag / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(HashtagModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'hashtag',
      protoPath: join(__dirname, 'src/grpc/hashtag.proto'),
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
github new-eden-social / new-eden-social / src / services / corporation / server.ts View on Github external
async function bootstrap() {
  const HTTP_PORT = parseInt(process.env.HTTP_PORT, 10) || 3000; // Default to 3000
  const GRPC_PORT = parseInt(process.env.GRPC_PORT, 10) || 4000; // Default to 4000

  const app = await NestFactory.create(CorporationModule);

  app.connectMicroservice({
    transport: Transport.GRPC,
    options: {
      url: `0.0.0.0:${GRPC_PORT}`,
      package: 'corporation',
      protoPath: join(__dirname, 'src/grpc/corporation.proto'),
    },
  });

  await app.startAllMicroservicesAsync();
  await app.listen(HTTP_PORT);
}
bootstrap();
github nestjs / nest / integration / microservices / e2e / sum-grpc.spec.ts View on Github external
beforeEach(async () => {
    const module = await Test.createTestingModule({
      controllers: [GrpcController],
    }).compile();

    server = express();
    app = module.createNestApplication(server);
    app.connectMicroservice({
      transport: Transport.GRPC,
      options: {
        package: 'math',
        protoPath: join(__dirname, '../src/grpc/math.proto'),
      },
    });
    await app.startAllMicroservicesAsync();
    await app.init();
  });
github notadd / notadd / src / grpc / grpc.client-factory.ts View on Github external
export function generateGrpcOptions(url: string, packageName: string, protoFileName: string): GrpcOptions {
    return {
        transport: Transport.GRPC,
        options: {
            url,
            package: packageName,
            protoPath: join(__dirname, 'protobufs/' + protoFileName),
            loader: {
                arrays: true
            }
        }
    };
}