-
Notifications
You must be signed in to change notification settings - Fork 54
/
client.go
50 lines (45 loc) · 1.05 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"time"
tp "github.com/henrylee2cn/teleport"
"github.com/henrylee2cn/teleport/socket/example/pb"
micro "github.com/xiaoenai/tp-micro"
"github.com/xiaoenai/tp-micro/discovery"
"github.com/xiaoenai/tp-micro/model/etcd"
)
func main() {
// discovery.SetServiceNamespace("test@")
tp.SetSocketNoDelay(false)
tp.SetShutdown(time.Second*20, nil, nil)
cli := micro.NewClient(
micro.CliConfig{
DefaultBodyCodec: "protobuf",
DefaultDialTimeout: time.Second * 5,
Failover: 3,
CircuitBreaker: micro.CircuitBreakerConfig{
Enable: true,
ErrorPercentage: 50,
},
HeartbeatSecond: 3,
},
discovery.NewLinker(etcd.EasyConfig{
Endpoints: []string{"http://127.0.0.1:2379"},
}),
)
defer cli.Close()
var reply = new(pb.PbTest)
rerr := cli.Pull(
"/group/home/test",
&pb.PbTest{A: 10, B: 2},
reply,
).Rerror()
if rerr != nil {
tp.Errorf("pull error: %v", rerr)
} else {
tp.Infof("pull reply: %v", reply)
}
// test heartbeat
time.Sleep(10e9)
cli.UsePullHeartbeat()
time.Sleep(10e9)
}