/
client.go
44 lines (34 loc) · 986 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
40
41
42
43
44
package main
import (
"context"
"flag"
"log"
"time"
example "github.com/rpcxio/rpcx-examples"
"github.com/smallnest/rpcx/client"
)
var (
addr1 = flag.String("addr1", "tcp@localhost:8972", "server address")
addr2 = flag.String("addr2", "tcp@localhost:8973", "server address")
)
func main() {
flag.Parse()
d := client.NewMultipleServersDiscovery([]*client.KVPair{{Key: *addr1, Value: "latitude=39.9289&longitude=116.3883"},
{Key: *addr2, Value: "latitude=139.3453&longitude=23.3243"}})
xclient := client.NewXClient("Arith", client.Failtry, client.ConsistentHash, d, client.DefaultOption)
defer xclient.Close()
xclient.ConfigGeoSelector(39.30, 116.40)
args := &example.Args{
A: 10,
B: 20,
}
for i := 0; i < 10; i++ {
reply := &example.Reply{}
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != nil {
log.Fatalf("failed to call: %v", err)
}
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
time.Sleep(time.Second)
}
}