feat: set default connection idle time for grpc servers (#1922)

* feat: set default connection idle time for grpc servers

* feat: add grpc health check
This commit is contained in:
Kevin Wan
2022-05-21 19:38:27 +08:00
committed by GitHub
parent 6b1e15cab1
commit ca88b69d24
2 changed files with 18 additions and 0 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/zeromicro/go-zero/core/stat"
"github.com/zeromicro/go-zero/zrpc/internal/serverinterceptors"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
)
type (
@@ -71,9 +72,15 @@ func (s *rpcServer) Start(register RegisterFn) error {
WithStreamServerInterceptors(streamInterceptors...))
server := grpc.NewServer(options...)
register(server)
// register the health check service
grpc_health_v1.RegisterHealthServer(server, s.health)
s.health.Resume()
// we need to make sure all others are wrapped up,
// so we do graceful stop at shutdown phase instead of wrap up phase
waitForCalled := proc.AddWrapUpListener(func() {
s.health.Shutdown()
server.GracefulStop()
})
defer waitForCalled()