2.0.0 • Published 2 years ago

@betsys-nestjs/grpc v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

gRPC library

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

Dependencies

PackageVersion
@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()
    }
}
1.2.0

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.2

3 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago