对健康检查协议感到困惑

问题描述

我已阅读以下文档,源代码和问题:

我提供一个示例并尝试说明:

// Import package
let health = require('grpc-health-check');

// Define service status map. Key is the service name,value is the corresponding status.
// By convention,the empty string "" key represents that status of the entire server.
const statusMap = {
  "ServiceFoo": proto.grpc.health.v1.HealthCheckResponse.ServingStatus.SERVING,"ServiceBar": proto.grpc.health.v1.HealthCheckResponse.ServingStatus.NOT_SERVING,"": proto.grpc.health.v1.HealthCheckResponse.ServingStatus.NOT_SERVING,};

// Construct the service implementation
let healthImpl = new health.Implementation(statusMap);

// Add the service and implementation to your pre-existing gRPC-node server
server.addService(health.service,healthImpl);

我不清楚以下几点:

  1. statusMap中的服务名称是否需要与协议缓冲区文件中的服务名称相同?或者可以任意指定服务名称。如果是这样,服务名称如何映射到协议缓冲区中定义的服务?

根据运行状况检查协议:

服务器应手动注册所有服务并设置各自的状态

  1. 为什么我们需要手动注册?如果可以生成服务代码,为什么grpc不能帮助我们在statusMap中自动注册服务名称? (想象一下,一站式设置100个服务的状态)

  2. 服务状态为硬代码,无法在应用程序运行时更改。如果由于某种原因(例如配置错误)在运行时我的服务不可用,则下游服务不可用,但是该服务的状态始终为服务状态(因为它是硬代码),如果是,则运行状况检查的含义是什么?>

对于RESTful API,我们可以提供/health-check/ping API,以检查整个服务器是否正常运行。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)