RPCX

一个简单快速的rpc服务发现与治理框架

官方网站

项目地址

快速开始

下载与安装

go get -v github.com/smallnest/rpcx/...

例子:简单rpcx服务

package protos

import "context"

type Args struct {
	A int
	B int
}

type Reply struct {
	C int
}

type Arith int

func (t *Arith) Mul(ctx context.Context, args *Args, reply *Reply) error {
	reply.C = args.A * args.B
	return nil
}

执行go run server/main.go启动rpcx服务

服务端输出

2019/06/25 19:38:45 server.go:174: ?[32mINFO ?[0m: server pid:15216

开启一个新的控制台,执行go run client/main.go

客户端输出

2019/06/25 19:39:04 10 * 20 = 200

服务端输出

2019/06/25 19:39:04 server.go:357: ?[32mINFO ?[0m: client has closed this connection: 127.0.0.1:52028

最后更新于