File

lib/health-indicators/microservice/grpc.health.ts

Description

The GRPCHealthIndicator is used for health checks related to GRPC

Extends

HealthIndicator

Example

Index

Methods

Constructor

constructor()

Initializes the health indicator

Methods

Async checkService
checkService(key: string, service: string, options: CheckGRPCServiceOptions)

Checks if the given service is up using the standart health check specification of GRPC.

https://github.com/grpc/grpc/blob/master/doc/health-checking.md

Parameters :
Name Type Optional Default value Description
key string No

The key which will be used for the result object

service string No

The service which should be checked

options CheckGRPCServiceOptions No {}

Configuration for the request

Example :
grpc.checkService('hero_service', 'hero.health.v1')
// Change the timeout
grpc.checkService('hero_service', 'hero.health.v1', { timeout: 300 })
// You can customize the health check
// by giving these options. Nonetheless it is still seen
// as best practice to implement the recommended GRPC specs
grpc.checkService('hero_service', 'hero.health.v1', {
timeout: 500,
package: 'grpc.health.v2',
protoPath: join(__dirname, './protos/my-custom-health.v1'),
// The name of the service you need for the health check
healthServiceName: 'Health',
// Your custom function which checks the service
healthServiceCheck: (healthService: any, service: string) =>
healthService.check({ service }).toPromise(),
})
Protected getStatus
getStatus(key: string, isHealthy: boolean, data?: literal type)

Generates the health indicator result object

Parameters :
Name Type Optional Description
key string No

The key which will be used as key for the result object

isHealthy boolean No

Whether the health indicator is healthy

data literal type Yes

Additional data which will get appended to the result object

result-matching ""

    No results matching ""