https://github.com/blackbeans/go-moa-client
go-moa-client is an easing way to use go-moa
https://github.com/blackbeans/go-moa-client
Last synced: 4 months ago
JSON representation
go-moa-client is an easing way to use go-moa
- Host: GitHub
- URL: https://github.com/blackbeans/go-moa-client
- Owner: blackbeans
- Created: 2016-03-28T03:18:55.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2023-05-29T03:18:41.000Z (about 3 years ago)
- Last Synced: 2024-06-20T13:37:57.880Z (almost 2 years ago)
- Language: Go
- Size: 314 KB
- Stars: 4
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### MOA Client使用方式
* 安装:
安装ZooKeeper (或者使用本地文件指定连接特定Server)
$Zookeeper/bin/zkServer.sh start
```
go get github.com/blackbeans/go-moa-client
```
* 定义服务的接口对应的struct
- 例如接口为:
```goalng
//接口
type IGoMoaDemo interface {
GetDemoName(serviceUri, proto string) (DemoResult, error)
}
转换为如下结构体
type GoMoaDemo struct {
GetDemoName func(serviceUri, proto string) (CDemoResult, error)
}
```
* 客户端启动:
```goalng
consumer := client.NewMoaConsumer("go_moa_client.toml",
[]proxy.Service{proxy.Service{
ServiceUri: "/service/bibi/go-moa",
Interface: &GoMoaDemo{}},
})
//获取调用实例
h := consumer.GetService("/service/bibi/go-moa").(*GoMoaDemo)
for i := 0; i < 10000; i++ {
a, err := h.GetDemoName("/service/user-profile", "redis")
fmt.Printf("GetDemoName|%s|%v\n", a, err)
}
```
* 说明
- Service为一个服务单元,对应了远程调用的服务名称、以及对应的接口
- MoaConsumer需要对应的Moa的配置文件,toml类型,具体配置参见conf/moa_client.toml
* Benchmark
env:Macbook Pro 2.2 GHz Intel Core i7
```golang
go test --bench=".*" github.com/blackbeans/go-moa-client/client -run=BenchmarkMakeRpcFunc
BenchmarkParallerMakeRpcFunc-8 50000 28315 ns/op
```