From 070fcafd7ff2d9ae06d8f26b934337f6b5d6c3d3 Mon Sep 17 00:00:00 2001 From: what Date: Fri, 9 Jun 2023 16:51:42 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E4=BF=AE=E6=94=B9=E5=BF=83=E8=B7=B3?= =?UTF-8?q?=E5=8C=85=E9=97=B4=E9=9A=94,=20=E9=81=BF=E5=85=8D=E5=A4=AA?= =?UTF-8?q?=E8=BF=87=E9=A2=91=E7=B9=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- grpcall.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/grpcall.go b/grpcall.go index a78ce40..e251a9a 100644 --- a/grpcall.go +++ b/grpcall.go @@ -134,13 +134,15 @@ func (this Grpcall) invokeServStream(ctx context.Context, stub grpcdynamic.Stub, go func() { msgParser := jsonpb.Marshaler{ - EmitDefaults: true, + OrigName: true, // 保留原始字段名 + EmitDefaults: true, // 包括默认值的字段也会被序列化 AnyResolver: anyResolver, } defer func() { cancel() pWriter.Close() + pReader.Close() }() for { @@ -467,8 +469,9 @@ func NewGrpcall(addr string, protosets []string, opts ...grpc.DialOption) (g *Gr opts = append(opts, grpc.WithKeepaliveParams(keepalive.ClientParameters{ - Time: 64 * time.Second, - Timeout: 64 * time.Second, + Time: 10 * time.Second, // 心跳包时间间隔 + Timeout: 5 * time.Second, // 心跳包超时时间 + PermitWithoutStream: true, // 允许在没有活动流时发送心跳包 }), grpc.WithBlock(), grpc.FailOnNonTempDialError(true),