New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nice-grpc-server-health

Package Overview
Dependencies
Maintainers
0
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nice-grpc-server-health

gRPC health checking protocol implementation for nice-grpc

  • 2.0.12
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
8.7K
decreased by-20.69%
Maintainers
0
Weekly downloads
 
Created
Source

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();

FAQs

Package last updated on 24 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc