initial import
This commit is contained in:
44
example/rpc/client/unary/client.go
Normal file
44
example/rpc/client/unary/client.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"zero/core/conf"
|
||||
"zero/example/rpc/remote/unary"
|
||||
"zero/rpcx"
|
||||
)
|
||||
|
||||
var configFile = flag.String("f", "config.json", "the config file")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var c rpcx.RpcClientConf
|
||||
conf.MustLoad(*configFile, &c)
|
||||
client := rpcx.MustNewClient(c)
|
||||
ticker := time.NewTicker(time.Millisecond * 500)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
conn, ok := client.Next()
|
||||
if !ok {
|
||||
log.Fatal("no server")
|
||||
}
|
||||
|
||||
greet := unary.NewGreeterClient(conn)
|
||||
resp, err := greet.Greet(context.Background(), &unary.Request{
|
||||
Name: "kevin",
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Println("X", err.Error())
|
||||
} else {
|
||||
fmt.Println("=>", resp.Greet)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
example/rpc/client/unary/config.json
Normal file
5
example/rpc/client/unary/config.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"Server": "localhost:3457",
|
||||
"App": "adhoc",
|
||||
"Token": "E0459CF7-EA85-4E0C-BB48-C81448811511"
|
||||
}
|
||||
8
example/rpc/client/unary/config_etcd.json
Normal file
8
example/rpc/client/unary/config_etcd.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Hosts": [
|
||||
"127.0.0.1:2379"
|
||||
],
|
||||
"Key": "sms",
|
||||
"App": "adhoc",
|
||||
"Token": "E0459CF7-EA85-4E0C-BB48-C81448811511"
|
||||
}
|
||||
Reference in New Issue
Block a user