@betsys-nestjs/grpc
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

gRPC library

This library is responsible bootstraping GRPC application and providing GRPC client for health checking.

Dependencies

Package Version
@grpc/grpc-js ^1.8.0
@nestjs/common ^10.0.0
@nestjs/microservices ^10.0.0
@nestjs/core ^10.0.0
@nestjs/terminus ^10.0.0
reflect-metadata ^0.1.13
rxjs ^7.8.0

Usage

To start using this library simply import GrpcBuilder in main.ts as an entry point of Nest application.

const {app, microservice} = await GrpcBuilder.createGrpcApplication(
    TestModule,
    {
        options: {
            url: '0.0.0.0:<port>',
            package: ['<package>'],
            protoPath: ['<protoPath>'],
            loader: {
                includeDirs: [
                    '<pathToProtobuff>'
                ],
            },
        },
        health: true,
    },
)

Then if you enable health checking for the GRPC you want to use GrpcHealthClientModule to initialize GRPC client for calling health check endpoint.

At the place where you want to use GRPC client simply do:

GrpcHealthClientModule.register(port, directoryOfProtofile)

You always need to define port, that would match the port of running GRPC server, and optionally you can define path of proto file with second parameter of register method.

Then you can inject service to any module and use it like this to call the actual health check method:

class HealthIndicator {
    constructor(private readonly grpcHealthClientService: GrpcHealthClientService) {
    }

    async isHealthy() {
        await this.grpcHealthClientService.check()
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @betsys-nestjs/grpc

Weekly Downloads

9

Version

2.0.0

License

MIT

Unpacked Size

10.3 kB

Total Files

14

Last publish

Collaborators

  • betsys-development
  • pawelnowak1
  • andrejsoucek
  • jammie88
  • jiraspe2
  • jakubschneller
  • javor454
  • krizacekcz
  • flyrell