motan-openresty
微博网格的 motan openresty
$ opm get idevz/motan-openresty
Motan-OpenResty
[!许可证] (https://github.com/weibocom/motan/blob/master/LICENSE)
概述 / 2017 年 10 月 17 日
[Motan][motan] 是一种跨语言的远程过程调用 (RPC) 框架,用于快速开发高性能的分布式服务。
此项目是 OpenResty Motan 实现。提供 OpenResty motan 服务器、motan 客户端。
特性
通过 motan2 协议与多种语言进行交互,例如 Java、PHP。
提供集群支持,并与流行的服务发现服务(如 [Consul][consul])集成。
支持高级调度功能,如加权负载均衡、跨 IDC 调度等。
针对高负载场景进行优化,在生产环境中提供高可用性。
快速入门
安装
git clone https://github.com/weibocom/motan-openresty.git motan
快速入门提供在同一台机器上运行客户端和服务器的非常基本的示例。有关使用和开发 Motan 的详细信息,请跳转到 文档。演示案例位于 examples/ 目录中。
Motan 服务器
创建 examples/motan-service/sys/MOTAN_SERVER_CONF 来配置服务
;config of registries
[motan.registry.consul-test-motan2]
protocol=consul
host=10.211.55.3
port=8500
registryRetryPeriod=30000
registrySessionTimeout=10000
requestTimeout=5000
;conf of services
[motan.basicRefer.simple_rpc_ref]
group=yf-api-core
registry=consul-test-motan2
serialization=simple
protocol=motan2
version=0.1
requestTimeout=1000
haStrategy=failover
loadbalance=random
filter=accessLog,metrics
maxClientConnection=10
minClientConnection=1
retries=0
application=whos-agent
[motan.service.or_service]
group=idevz-test-static
path=com.weibo.motan.status
registry=consul-test-motan2
version=1
port=1234
protocol=motan2
serialization=simple
basicRefer=simple_rpc_service
编写一个实现,创建并启动 RPC 服务器:examples/motan-service/status.lua。
local setmetatable = setmetatable
local _M = {
_VERSION = '0.0.1'
}
local mt = {__index = _M}
function _M.new(self, opts)
return setmetatable({}, mt)
end
function _M.show_batch(self, opts)
return "--> Motan" .. "->not name----->\n" .. sprint_r(opts) .. num
end
return _M
Motan 客户端
创建 examples/motan-service/sys/MOTAN_CLIENT_CONF 来配置用于订阅的服务
;config of registries
[motan.registry.consul-test-motan2]
protocol=consul
host=10.211.55.3
port=8500
registryRetryPeriod=30000
registrySessionTimeout=10000
requestTimeout=5000
;conf of refers
[motan.basicRefer.simple_rpc_ref]
group=yf-api-core
registry=vintage-online
serialization=simple
protocol=motan2
version=0.1
requestTimeout=1000
haStrategy=failover
loadbalance=random
filter=accessLog,metrics
maxClientConnection=10
minClientConnection=1
retries=0
application=whos-agent
[motan.refer.rpc_test]
group=idevz-test-static
path=com.weibo.motan.status
registry=consul-test-motan2
protocol=motan2
serialization=simple
basicRefer=simple_rpc_ref
开始调用
local singletons = require "motan.singletons"
local serialize = require "motan.serialize.simple"
local client_map = singletons.client_map
local client = client_map["rpc_test"]
local res = client:show_batch({name = "idevz"})
print_r("<pre/>")
print_r(serialize.deserialize(res.body))
文档
贡献者
周晶 (@idevz)
Ray (@rayzhang0603)
xiaohutuer (@xiaohutuer)
Arthur Guo (@jealone)
huzhongx (@huzhongx)
dingzk (@dingzk)
许可证
Motan 在 Apache 许可证 2.0 下发布。
[motan]:https://github.com/weibocom/motan [consul]:http://www.consul.io
作者
zhoujing2 "idevz" zhou (idevz)
许可证
apache2