Motan在注册中心的服务是以group的形式保存的,一般推荐一个分组以机房+业务线进行命名,如yf-user-rpc。一个分组中包含若干的Service,一个Service即是java中的一个接口类名,每个Service下有一组能够提供对应服务的Server。
<motan:basicService .../>
rpc服务的通用配置,用于配置所有服务接口的公共配置,减少配置冗余。basicService包含以下常用属性:
-
- id:标识配置项
- export:标识服务的暴露方式,格式为“protocolId:port”(使用的协议及对外提供的端口号),其中protocolId:应与motan:protocol中的id一致
- group:标识服务的分组
- module:标识模块信息
- registry:标识service使用的注册中心,与motan:registry中的name对应
motan:service可以通过以下方式引用基本配置。
<!-- 通用配置,多个rpc服务使用相同的基础配置. group和module定义具体的服务池。export格式为“protocol id:提供服务的端口” -->
<motan:basicService id="serviceBasicConfig" export="demoMotan:8002" group="motan-demo-rpc" module="motan-demo-rpc" registry="registry"/>
<!-- 通用配置,多个rpc服务使用相同的基础配置. group和module定义具体的服务池。export格式为“protocol id:提供服务的端口” -->
<motan:service interface="com.weibo.motan.demo.service.MotanDemoService" ref="demoServiceImpl" basicService="serviceBasicConfig"/>
motan:service中的basicService属性用来标识引用哪个motan:basicService对象,对于basicService中已定义的内容,service不必重复配置。
下表是service的所有属性说明:
Property name |
Type |
Default |
Comment |
export |
String |
|
服务暴露的方式,包含协议及端口号,多个协议端口用"," 分隔 |
basicService |
|
|
基本service配置 |
interface |
Class |
|
服务接口名 |
ref |
String |
|
接口实现的类 |
class |
String |
|
实现service的类名 |
host |
String |
|
如果有多个ip,但只想暴露指定的某个ip,设置该参数 |
path |
String |
|
服务路径 |
serialization |
String |
hessian2 |
序列化方式 |
extConfig |
String |
|
扩展配置 |
proxy |
String |
|
代理类型 |
group |
String |
default_rpc |
服务分组 |
version |
String |
1.0 |
版本 |
throwException |
String |
true |
抛出异常 |
requestTimeout |
String |
200 |
(目前未用)请求超时时间(毫秒) |
connectTimeout |
String |
1000 |
(目前未用)连接超时时间(毫秒) |
retries |
int |
0 |
(目前未用)重试次数 |
filter |
String |
|
过滤器配置 |
listener |
String |
|
监听器配置 |
connections |
int |
|
连接数限制,0表示共享连接,否则为该服务独享连接数;默认共享 |
application |
String |
motan |
应用信息 |
module |
String |
motan |
模块信息 |
shareChannel |
boolean |
false |
是否共享channel |
timeout |
int |
|
方法调用超时时间 |
actives |
int |
0 |
最大请求数,0为不做并发限制 |
async |
boolean |
false |
方法是否异步 |
mock |
String |
false |
设为true,表示使用缺省Mock类名,即:接口名+Mock 后缀,服务接口调用失败Mock实现类 |
check |
boolean |
true |
检查服务提供者是否存在 |
registry |
String |
|
注册中心的id 列表,多个用“,”分隔,如果为空,则使用所有的配置中心 |
register |
boolean |
true |
在该注册中心上服务是否暴露 |
subscribe |
boolean |
true |
在该注册中心上服务是否引用 |
accessLog |
String |
false |
设为true,将向logger 中输出访问日志 |
usegz |
boolean |
false |
是否开启gzip压缩.只有compressMotan的codec才能支持 |
mingzSize |
int |
1000 |
开启gzip压缩的阈值.usegz开关开启,且传输数据大于此阈值时,才会进行gzip压缩。只有compressMotan的codec才能支持 |
codec |
String |
motan |
协议编码 |
<motan:referer/>和<motan:basicReferer/>
protocol、basic referer、extConfig、referer中定义相同属性时,优先级为referer > extConfig > basic referer > protocol