-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
39 lines (32 loc) · 858 Bytes
/
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
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"fmt"
"github.com/smartwalle/ngrpc"
"github.com/smartwalle/ngrpc/examples"
"github.com/smartwalle/ngrpc/examples/proto"
"github.com/smartwalle/ngrpc/registry/etcd"
"google.golang.org/grpc"
"log"
"time"
)
func main() {
var r = etcd.NewRegistry(examples.GetETCDClient())
var conn = ngrpc.Dial(
r.BuildPath("grpc1", "hello", "cmd1"),
ngrpc.WithInsecure(),
ngrpc.WithTimeout(time.Second*3),
grpc.WithDefaultServiceConfig(fmt.Sprintf(`{"LoadBalancingPolicy": "round_robin"}`)),
)
var client = proto.NewHelloWorldClient(conn)
for i := 0; i < 100; i++ {
rsp, err := client.Call(context.Background(), &proto.Hello{Name: "Coffee"})
if err != nil {
log.Println(context.Background(), err)
return
}
log.Println(context.Background(), i, rsp.Message)
time.Sleep(time.Second * 1)
}
r.Close()
}