Ai
1 Star 0 Fork 0

yonglinux/rpcx-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
client.go 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
鸟窝 提交于 2020-05-04 11:03 +08:00 . move examples to rpcxio/rpcx-examples
package main
import (
"context"
"flag"
"log"
"time"
"github.com/nacos-group/nacos-sdk-go/common/constant"
example "github.com/rpcxio/rpcx-examples"
"github.com/smallnest/rpcx/client"
)
func main() {
flag.Parse()
d := configNacos()
xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, client.DefaultOption)
defer xclient.Close()
args := &example.Args{
A: 10,
B: 20,
}
for {
reply := &example.Reply{}
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != nil {
log.Printf("failed to call: %v\n", err)
time.Sleep(5 * time.Second)
continue
}
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
time.Sleep(5 * time.Second)
}
}
func configNacos() client.ServiceDiscovery {
clientConfig := constant.ClientConfig{
TimeoutMs: 10 * 1000,
ListenInterval: 30 * 1000,
BeatInterval: 5 * 1000,
NamespaceId: "public",
CacheDir: "./cache",
LogDir: "./log",
UpdateThreadNum: 20,
NotLoadCacheAtStart: true,
UpdateCacheWhenEmpty: true,
}
serverConfig := []constant.ServerConfig{{
IpAddr: "console.nacos.io",
Port: 80,
}}
return client.NewNacosDiscovery("Arith", "test", clientConfig, serverConfig)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yonglinux/rpcx-examples.git
git@gitee.com:yonglinux/rpcx-examples.git
yonglinux
rpcx-examples
rpcx-examples
v1.1.6

搜索帮助