1 Star 0 Fork 0

yonglinux / rpcx-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
client.go 865 Bytes
一键复制 编辑 原始数据 按行查看 历史
鸟窝 提交于 2020-05-04 11:03 . move examples to rpcxio/rpcx-examples
package main
import (
"context"
"flag"
"log"
example "github.com/rpcxio/rpcx-examples"
"github.com/smallnest/rpcx/client"
)
var (
addr1 = flag.String("addr1", "tcp@localhost:8972", "server1 address")
addr2 = flag.String("addr2", "tcp@localhost:9981", "server2 address")
)
func main() {
flag.Parse()
d := client.NewMultipleServersDiscovery([]*client.KVPair{{Key: *addr1}, {Key: *addr2}})
option := client.DefaultOption
option.Retries = 10
xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, option)
defer xclient.Close()
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.Printf("failed to call: %v", err)
} else {
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}
}
}
1
https://gitee.com/yonglinux/rpcx-examples.git
git@gitee.com:yonglinux/rpcx-examples.git
yonglinux
rpcx-examples
rpcx-examples
v1.1.6

搜索帮助