其他分享
首页 > 其他分享> > grpc 使用压缩器 compressor

grpc 使用压缩器 compressor

作者:互联网

 Basics tutorial | Go | gRPC https://grpc.io/docs/languages/go/basics/

"google.golang.org/grpc"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/metadata"




lis, err := net.Listen("tcp", port)
if err != nil {

}
// TODO
sp := keepalive.ServerParameters{
MaxConnectionIdle: 128 * time.Second,
MaxConnectionAge: 128 * time.Second,
MaxConnectionAgeGrace: 128 * time.Second,
Time: 128 * time.Second,
Timeout: 128 * time.Second,
}

_defaultServerMaxReceiveMessageSize := 1024 * 1024 * 4 * 4

so := grpc.MaxRecvMsgSize(_defaultServerMaxReceiveMessageSize)

so1 := grpc.KeepaliveParams(sp)
grpc.UseCompressor(gzip.Name)
s := grpc.NewServer(so, so1)
pb.RegisterCISServer(s, &server{})
// ?? TODO
reflection.Register(s)
if err := s.Serve(lis); err != nil {
}


bytes := 1024 * 1024 * 4 * 4
cp := grpc.ConnectParams{}
cp.MinConnectTimeout = 16 * time.Second
co := grpc.UseCompressor(gzip.Name)
conn, err := grpc.Dial(conf.SrvAddr+":60053", grpc.WithInsecure(), grpc.WithBlock(), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(bytes)),
grpc.WithConnectParams(cp), grpc.WithDefaultCallOptions(co),
)

 

标签:1024,err,grpc,compressor,Second,压缩器,time,128
来源: https://www.cnblogs.com/rsapaper/p/15507428.html