feat 初次提交
This commit is contained in:
30
net/grpc/resolver/conn.go
Normal file
30
net/grpc/resolver/conn.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package resolver
|
||||
|
||||
import (
|
||||
"common/log"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
"google.golang.org/grpc/keepalive"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewGrpcConnection(target string) (*grpc.ClientConn, error) {
|
||||
cc, err := grpc.NewClient(
|
||||
target,
|
||||
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||
grpc.WithDefaultServiceConfig(`{"loadBalancingConfig": [{"round_robin": {}}]}`),
|
||||
grpc.WithKeepaliveParams(
|
||||
keepalive.ClientParameters{
|
||||
Time: 30 * time.Second, // 保活探测包发送的时间间隔
|
||||
Timeout: 10 * time.Second, // 保活探测包的超时时间
|
||||
PermitWithoutStream: true,
|
||||
},
|
||||
),
|
||||
//grpc.WithStatsHandler(&StatsHandler{}),
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("create grpc err: %v, target: %v", err, target)
|
||||
return nil, err
|
||||
}
|
||||
return cc, nil
|
||||
}
|
||||
Reference in New Issue
Block a user