1 Star 0 Fork 0

yonglinux / rpcx-sun-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client.go 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
root 提交于 2022-02-17 17:49 . update
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)
}
}
1
https://gitee.com/yonglinux/rpcx-sun-examples.git
git@gitee.com:yonglinux/rpcx-sun-examples.git
yonglinux
rpcx-sun-examples
rpcx-sun-examples
v1.1.8

搜索帮助