2.0.10 • Published 2 months ago

nice-grpc-server-health v2.0.10

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

nice-grpc-server-health npm version

Health Checking Protocol implementation for nice-grpc.

This package enables you to use tools like grpc-health-probe with your gRPC server.

In Kubernetes, gRPC probes are supported natively.

Installation

npm install nice-grpc-server-health

Usage

Basic

For the simplest usage, just add the Health service implementation to your server. The server will be considered healthy while it is able to accept requests.

import {createServer} from 'nice-grpc';
import {HealthDefinition, HealthServiceImpl} from 'nice-grpc-server-health';

const server = createServer();

server.add(HealthDefinition, HealthServiceImpl());

Advanced

You can control the health state of the server or per-service with HealthState object:

import {createServer} from 'nice-grpc';
import {
  HealthDefinition,
  HealthServiceImpl,
  HealthState,
} from 'nice-grpc-server-health';

const server = createServer();

const healthState = HealthState();

server.add(HealthDefinition, HealthServiceImpl(healthState));
// Add our own service
server.add(MyService, myServiceImpl);

// Set the server status to `unhealthy`. The default server status is `healthy`.
healthState.setStatus('unhealthy');
// Set the `MyService` status to `unhealthy` by specifying fully-qualified name.
// The default service status is `unknown`.
healthState.setStatus('unhealthy', MyService.fullName);

// ...

healthState.setStatus('healthy');
healthState.setStatus('healthy', MyService.fullName);

This package also supports the Watch method that is able to send real-time updates of health statuses. Since the Watch method returns infinite stream, it is recommended to use the terminator middleware:

import {createServer} from 'nice-grpc';
import {HealthDefinition, HealthServiceImpl} from 'nice-grpc-server-health';
import {TerminatorMiddleware} from 'nice-grpc-server-middleware-terminator';

const terminatorMiddleware = TerminatorMiddleware();

const server = createServer().use(terminatorMiddleware);
server.add(HealthDefinition, HealthServiceImpl());
await server.listen('0.0.0.0:8080');

// ... terminate middleware before shutdown:

terminatorMiddleware.terminate();
await server.shutdown();
2.0.10

2 months ago

2.0.9

7 months ago

2.0.8

7 months ago

2.0.7

10 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.5

1 year ago

2.0.4

1 year ago

2.0.6

1 year ago

2.0.1

2 years ago

1.1.1

2 years ago

1.1.2

2 years ago

2.0.0

2 years ago

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.2

2 years ago

1.0.3

2 years ago

1.0.1

3 years ago

1.0.0

3 years ago