代码拉取完成,页面将自动刷新
package main
import (
"context"
"flag"
"log"
"time"
"github.com/nacos-group/nacos-sdk-go/common/constant"
example "github.com/rpcxio/rpcx-examples"
nclient "github.com/rpcxio/rpcx-nacos/client"
"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, error) {
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 nclient.NewNacosDiscovery("Arith", "test", clientConfig, serverConfig)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。