[fix] 修改心跳包间隔, 避免太过频繁

This commit is contained in:
what 2023-06-09 16:51:42 +08:00
parent 5f50e424be
commit 070fcafd7f

View File

@ -134,13 +134,15 @@ func (this Grpcall) invokeServStream(ctx context.Context, stub grpcdynamic.Stub,
go func() { go func() {
msgParser := jsonpb.Marshaler{ msgParser := jsonpb.Marshaler{
EmitDefaults: true, OrigName: true, // 保留原始字段名
EmitDefaults: true, // 包括默认值的字段也会被序列化
AnyResolver: anyResolver, AnyResolver: anyResolver,
} }
defer func() { defer func() {
cancel() cancel()
pWriter.Close() pWriter.Close()
pReader.Close()
}() }()
for { for {
@ -467,8 +469,9 @@ func NewGrpcall(addr string, protosets []string, opts ...grpc.DialOption) (g *Gr
opts = append(opts, opts = append(opts,
grpc.WithKeepaliveParams(keepalive.ClientParameters{ grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: 64 * time.Second, Time: 10 * time.Second, // 心跳包时间间隔
Timeout: 64 * time.Second, Timeout: 5 * time.Second, // 心跳包超时时间
PermitWithoutStream: true, // 允许在没有活动流时发送心跳包
}), }),
grpc.WithBlock(), grpc.WithBlock(),
grpc.FailOnNonTempDialError(true), grpc.FailOnNonTempDialError(true),