第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何實(shí)現(xiàn)go grpc-go健康檢查?

如何實(shí)現(xiàn)go grpc-go健康檢查?

Go
縹緲止盈 2023-08-14 15:09:23
我正在尋找grpc-go健康檢查的文檔和代碼示例。尋找問(wèn)題https://github.com/grpc/grpc-go/issues/448https://github.com/grpc/grpc-go/issues/2770沒(méi)有明確的答案可以在我的程序中重復(fù)使用來(lái)實(shí)施健康檢查。
查看完整描述

3 回答

?
慕仙森

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

如果您不想使用該庫(kù),您可以像這樣實(shí)現(xiàn)健康檢查:

import (

? ? "google.golang.org/grpc/health"

? ? "google.golang.org/grpc/health/grpc_health_v1"

)

grpcServer := grpc.NewServer()

grpc_health_v1.RegisterHealthServer(grpcServer, health.NewServer())


查看完整回答
反對(duì) 回復(fù) 2023-08-14
?
哆啦的時(shí)光機(jī)

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊

您現(xiàn)在應(yīng)該實(shí)現(xiàn)該邏輯,并在您的服務(wù)集中注冊(cè)該服務(wù)。

自述文件建議手動(dòng)將服務(wù)注冊(cè)到運(yùn)行狀況檢查服務(wù)中,以便您可以將服務(wù)列表作為參數(shù)傳遞來(lái)創(chuàng)建運(yùn)行狀況檢查服務(wù)。

我建議為您的服務(wù)定義一個(gè)接口,以便健康檢查服務(wù)可以以相同的方式處理所有這些服務(wù):

type HealthMeter interface {

? ? GetHealth() mysample.HealthCheckResponse_ServingStatus

? ? WatchHealth() <- chan mysample.HealthCheckResponse_ServingStatus

}


// implement service "A" and "B" as both interfaces (gRPC server AND HealthMeter)


grpcServer := grpc.NewServer()

srvA := servers.NewServiceA()

srvB := servers.NewServiceB()

healthSrv := servers.NewHealthCheckServer(map[string]servers.HealthMeter{

? ? "serviceA": srvA,

? ? "serviceB": srvB,

})


mysample.RegisterServiceAServer(grpcServer, srvA)

mysample.RegisterServiceBServer(grpcServer, srvB)

mysample.RegisterHealthServer(grpcServer, healthSrv)

我希望它可以幫助你。


查看完整回答
反對(duì) 回復(fù) 2023-08-14
?
Smart貓小萌

TA貢獻(xiàn)1911條經(jīng)驗(yàn) 獲得超7個(gè)贊

在 grpc 包中實(shí)現(xiàn)健康檢查示例的最簡(jiǎn)單方法

/*

?*

?* Copyright 2020 gRPC authors.

?*

?* Licensed under the Apache License, Version 2.0 (the "License");

?* you may not use this file except in compliance with the License.

?* You may obtain a copy of the License at

?*

?*? ? ?http://www.apache.org/licenses/LICENSE-2.0

?*

?* Unless required by applicable law or agreed to in writing, software

?* distributed under the License is distributed on an "AS IS" BASIS,

?* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

?* See the License for the specific language governing permissions and

?* limitations under the License.

?*

?*/


// Binary server is an example server.

package main


import (

? ? "context"

? ? "flag"

? ? "fmt"

? ? "log"

? ? "net"

? ? "time"


? ? "google.golang.org/grpc"

? ? pb "google.golang.org/grpc/examples/features/proto/echo"

? ? "google.golang.org/grpc/health"

? ? healthgrpc "google.golang.org/grpc/health/grpc_health_v1"

? ? healthpb "google.golang.org/grpc/health/grpc_health_v1"

)


var (

? ? port? = flag.Int("port", 50051, "the port to serve on")

? ? sleep = flag.Duration("sleep", time.Second*5, "duration between changes in health")


? ? system = "" // empty string represents the health of the system

)


type echoServer struct {

? ? pb.UnimplementedEchoServer

}


func (e *echoServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {

? ? return &pb.EchoResponse{

? ? ? ? Message: fmt.Sprintf("hello from localhost:%d", *port),

? ? }, nil

}


var _ pb.EchoServer = &echoServer{}


func main() {

? ? flag.Parse()


? ? lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))

? ? if err != nil {

? ? ? ? log.Fatalf("failed to listen: %v", err)

? ? }


? ? s := grpc.NewServer()

? ? healthcheck := health.NewServer()

? ? healthgrpc.RegisterHealthServer(s, healthcheck)

? ? pb.RegisterEchoServer(s, &echoServer{})


? ? go func() {

? ? ? ? // asynchronously inspect dependencies and toggle serving status as needed

? ? ? ? next := healthpb.HealthCheckResponse_SERVING


? ? ? ? for {

? ? ? ? ? ? healthcheck.SetServingStatus(system, next)


? ? ? ? ? ? if next == healthpb.HealthCheckResponse_SERVING {

? ? ? ? ? ? ? ? next = healthpb.HealthCheckResponse_NOT_SERVING

? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? next = healthpb.HealthCheckResponse_SERVING

? ? ? ? ? ? }


? ? ? ? ? ? time.Sleep(*sleep)

? ? ? ? }

? ? }()


? ? if err := s.Serve(lis); err != nil {

? ? ? ? log.Fatalf("failed to serve: %v", err)

? ? }

}


查看完整回答
反對(duì) 回復(fù) 2023-08-14
  • 3 回答
  • 0 關(guān)注
  • 211 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)