4 Star 0 Fork 0

wanttobeamaster / elasticell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rpc.go 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
wanttobeamaster 提交于 2021-04-05 17:12 . first
// Copyright 2016 DeepFabric, Inc.
//
// 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,
// See the License for the specific language governing permissions and
// limitations under the License.
package pdserver
import (
"net"
"github.com/fagongzi/log"
"gitee.com/wanttobeamaster/elasticell/pkg/pb/pdpb"
"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)
func (s *Server) startRPC() {
defer func() {
if err := recover(); err != nil {
log.Errorf("rpc: crash, errors:\n %+v", err)
}
}()
lis, err := net.Listen("tcp", s.cfg.AddrRPC)
if err != nil {
log.Fatalf("bootstrap: start grpc server failure, listen=<%s> errors:\n %+v",
s.cfg.AddrRPC,
err)
return
}
s.rpcServer = grpc.NewServer()
pdpb.RegisterPDServiceServer(s.rpcServer, NewRPCHandler(s))
reflection.Register(s.rpcServer)
if err := s.rpcServer.Serve(lis); err != nil {
if !s.callStop {
log.Fatalf("bootstrap: start grpc server failure, listen=<%s> errors:\n %+v",
s.cfg.AddrRPC,
err)
}
return
}
log.Infof("stop: grpc server stopped, addr=<%s>", s.cfg.AddrRPC)
}
func (s *Server) closeRPC() {
if s.rpcServer != nil {
s.rpcServer.GracefulStop()
}
}
Go
1
https://gitee.com/wanttobeamaster/elasticell.git
git@gitee.com:wanttobeamaster/elasticell.git
wanttobeamaster
elasticell
elasticell
8b1bff0b0046

搜索帮助