# go-moa-client **Repository Path**: blackbeans/go-moa-client ## Basic Information - **Project Name**: go-moa-client - **Description**: go-moa-client is an easing way to use go-moa - **Primary Language**: Go - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 8 - **Forks**: 0 - **Created**: 2016-05-12 - **Last Updated**: 2025-08-25 ## Categories & Tags **Categories**: message-server **Tags**: None ## README #### MOA Client使用方式 * Usage [样例参考](https://github.com/blackbeans/go-moa-demo) * 安装: 安装ZooKeeper $Zookeeper/bin/zkServer.sh start ``` go get github.com/blackbeans/go-moa-client/client go get github.com/blackbeans/go-moa/proxy ``` * 定义服务的接口对应的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 go test --bench=".*" github.com/blackbeans/go-moa-client/client -run=BenchmarkMakeRpcFunc BenchmarkMakeRpcFunc-8 20000 64517 ns/op * redis-benchmark - env:Macbook Pro 2.2 GHz Intel Core i7 - go run github.com/blackbeans/go-moa-client/benchmark.go redis-benchmark -h host -p 13000 -n 1000000 -c 100 get '{"action":"/service/bibi/go-moa","params":{"m":"setName","args":["a"]}}'