NamingService

  • gRPC服务地址:/fusion.discoveryx.grpc.NamingService
  • REST URL前缀:/fusion/discoveryx/v1/naming

REST URL路径由 REST URL前缀 + 服务名组织,均使用 POST 方法的请求,JSON序例化格式。如查询实例接口访问地址为:POST /fusion/discoveryx/v1/naming/QueryInstance。Protobuf与JSON格式转换请参阅: JSON 说明

RegisterInstance

gRPC

// 注册实例
rpc RegisterInstance (fusion.discoveryx.model.InstanceRegister) returns (fusion.discoveryx.model.NamingReply) {
}

请求

message InstanceRegister {
    // Instance namespace.
    string namespace = 1;
    // Instance serviceName.
    string service_name = 2;
    // The instance group name needs to be the same as service group name, otherwise the service group name will be overwritten.
    string group_name = 3;
    // Instance local ip.
    string ip = 4;
    // Instance local port.
    int32 port = 5;
    // Instance query weight, the default value is 1.0.
    double weight = 6;
    // instance health status. If set to true, it will be available immediately. Otherwise, it will be available after the first heartbeat detection is successful. The default value is false.
    bool health = 7;
    // If instance is enabled to accept request, the default value is false.
    bool enable = 8;
    // If instance is ephemeral, the default value is false.
    bool ephemeral = 9;
    // user extended attributes
    map<string, string> metadata = 10;
    // Healthy check method, the default value is HealthyCheckMethod.CLIENT_REPORT
    HealthyCheckMethod healthy_check_method = 11;
    // Healthy check per N seconds
    int32 healthy_check_interval = 12;
    // Unhealthy check count
    int32 unhealthy_check_count = 13;
    // Healthy check protocol
    HealthyCheckProtocol protocol = 14;
    // Whether TLS(HTTPS) is used for gRPC connection, the default value is false.
    bool use_tls = 15;
    // HTTP healthy check uri path.
    string http_path = 16;
}

响应

message NamingReply {
    int32 status = 1;
    string message = 2;
    oneof data {
        Instance instance = 3;
        ServiceInfo service_info = 4;
    }
}

Instance

oneofinstance字段将返回已注册实例信息,如下:


// 健康检查方式 enum HealthyCheckMethod { NOT_SET = 0; CLIENT_REPORT = 1; SERVER_SNIFF = 2; } enum HealthyCheckProtocol { UNKNOWN = 0; TCP = 1; HTTP = 2; // UDP = 3; } message Instance { // unique id of this instance. string instance_id = 1; // instance ip string ip = 2; // instance port int32 port = 3; // instance weight double weight = 4; // instance health status bool healthy = 5; // If instance is enabled to accept request bool enabled = 6; // If instance is ephemeral bool ephemeral = 7; // user extended attributes map<string, string> metadata = 8; // Healthy check method, the default value is HealthyCheckMethod.CLIENT_REPORT HealthyCheckMethod healthy_check_method = 9; // Healthy check per N seconds int32 healthy_check_interval = 10; // Unhealthy check count int32 unhealthy_check_count = 11; // Healthy check protocol HealthyCheckProtocol protocol = 12; // Whether TLS(HTTPS) is used for gRPC connection, the default value is false. bool use_tls = 13; // HTTP healthy check uri path. string http_path = 14; }

RemoveInstance

gRPC

// 删除实例
rpc RemoveInstance (fusion.discoveryx.model.InstanceRemove) returns (fusion.discoveryx.model.NamingReply) {
}

请求

message InstanceRemove {
    string namespace = 1;
    string service_name = 2;
    string instance_id = 3;
}

响应

删除实例没有oneof字段返回。

message NamingReply {
    int32 status = 1;
    string message = 2;
    oneof data {
        Instance instance = 3;
        ServiceInfo service_info = 4;
    }
}

QueryInstance

gRPC

// 查询实例
rpc QueryInstance (fusion.discoveryx.model.InstanceQuery) returns (fusion.discoveryx.model.NamingReply) {
}

请求

message InstanceQuery {
    string namespace = 1;
    string service_name = 2;
    string group_name = 3;
    // only return all healthy instances
    bool all_healthy = 4;
    // only return one healthy instance
    bool one_healthy = 5;
}

响应

message NamingReply {
    int32 status = 1;
    string message = 2;
    oneof data {
        Instance instance = 3;
        ServiceInfo service_info = 4;
    }
}

查询成功oneof通过queried字段将查询匹配到的实例返回:

ModifyInstance

gRPC

// 修改实例
rpc ModifyInstance (fusion.discoveryx.model.InstanceModify) returns (fusion.discoveryx.model.NamingReply) {
}

请求

message InstanceModify {
    string namespace = 1;
    string service_name = 2;
    string instance_id = 3;
    google.protobuf.StringValue group_name = 4;
    google.protobuf.StringValue ip = 5;
    google.protobuf.Int32Value port = 6;
    // instance weight
    google.protobuf.DoubleValue weight = 7;
    // instance health status
    google.protobuf.BoolValue health = 8;
    // If instance is enabled to accept request
    google.protobuf.BoolValue enable = 9;
    // user extended attributes
    map<string, string> metadata = 10;
    // true:replace old metadata, false: merge old metadata
    bool replace_metadata = 11;
    HealthyCheckMethod healthy_check_method = 12;
    // Healthy check per N seconds
    google.protobuf.Int32Value healthy_check_interval = 13;
    // Unhealthy check count
    google.protobuf.Int32Value unhealthy_check_count = 14;
    // 实例协议
    HealthyCheckProtocol protocol = 15;
    google.protobuf.BoolValue use_tls = 16;
    google.protobuf.StringValue http_path = 17;
}

响应

message NamingReply {
    int32 status = 1;
    string message = 2;
    oneof data {
        Instance instance = 3;
        ServiceInfo service_info = 4;
    }
}

oneofinstance字段将返回修改后的实例信息。

Heartbeat

gRPC

// 实例心跳消息。namespace, serviceName, ip, port, instanceId等使用metadata(HTTP Header发送)
//- `x-discoveryx-namespace`:命名空间
//- `x-discoveryx-service-name`:服务名
//- `x-discoveryx-ip`:服务监听IP地址
//- `x-discoveryx-port`:服务监听网络端口
//- `x-discoveryx-instance-id`:实例ID
rpc Heartbeat (stream fusion.discoveryx.model.InstanceHeartbeat) returns (stream fusion.discoveryx.model.ServerStatusBO) {
}

Heartbeat接口第一次调用时需要通过metadata(HTTP Header)传递以下内容:

  • x-discoveryx-namespace:命名空间
  • x-discoveryx-service-name:服务名
  • x-discoveryx-ip:服务监听IP地址
  • x-discoveryx-port:服务监听网络端口
  • x-discoveryx-instance-id:实例ID
在此文档中发现错误?该页面的源代码可以在 这里 找到。欢迎随时编辑并提交Pull Request。