henrylee2cn简单的rpc服务

server 端
package controllers import (
"github.com/henrylee2cn/teleport"
"model/system"
"log"
) type System struct {
tp.PullCtx
} func (p *System) GetServerTime(args *system.SystemTimeArg) (reply system.SystemTime,err *tp.Rerror){ log.Println(args.Token) reply = system.SystemTime{
Time:golibs.StandardTime(),
}
return reply,nil
}
client 端
var (
cli *micro.Client
rerr *tp.Rerror
) func init() {
tp.SetLoggerLevel("OFF")
cli = micro.NewClient(
micro.CliConfig{},
micro.NewStaticLinker(":6666"),
)
} func main() {
for i := 0; i < 10; i++ {
go func(i int) {
execute(i)
}(i)
} time.Sleep(math.MaxInt64)
} func execute(i int) {
var reply system.SystemTime
rerr = cli.Pull("/system/get_server_time", &system.SystemTimeArg{
Token: "sdasdasdasd",
}, &reply).Rerror()
if rerr != nil {
log.Fatalf("线程%d出错:%v", i, rerr)
}
log.Printf("跑了第%d轮", i)
log.Print(reply.Time) }
上一篇:Java高并发综合


下一篇:android手机两种方式获取IP地址