generated from Jille/raft-grpc-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
30 lines (28 loc) · 1.1 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package cluster
import (
clusterPb "github.com/Kapperchino/jet-stream/cluster/proto/proto"
grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
"github.com/rs/zerolog/log"
"google.golang.org/grpc"
"time"
)
func CreateClusterClient(address string) (clusterPb.ClusterMetaServiceClient, error) {
serviceConfig := `{"healthCheckConfig": {"serviceName": "Example"}, "loadBalancingConfig": [ { "round_robin": {} } ]}`
retryOpts := []grpc_retry.CallOption{
grpc_retry.WithBackoff(grpc_retry.BackoffExponential(100 * time.Millisecond)),
grpc_retry.WithMax(5),
}
maxSize := 1 * 1024 * 1024 * 1024
conn, err := grpc.Dial(address,
grpc.WithDefaultServiceConfig(serviceConfig), grpc.WithInsecure(),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true),
grpc.MaxCallRecvMsgSize(maxSize),
grpc.MaxCallSendMsgSize(maxSize)),
grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(retryOpts...)))
if err != nil {
log.Err(err).Msgf("Error creating connection for clusterService at port %s", address)
return nil, err
}
client := clusterPb.NewClusterMetaServiceClient(conn)
return client, nil
}