服务提供者
<!-- 提供方应用信息,用于计算依赖关系 值一般为项目名 -->
<dubbo:application name="project_name" />
<!-- 使用zookeeper广播注册中心暴露服务地址 -->
<dubbo:registry id="registry" protocol="zookeeper" address="224.5.6.7:1234"/>
<!-- 用dubbo协议在20880端口暴露服务 -->
<dubbo:protocol name="dubbo"port="20880"/>
<!-- 声明需要暴露的服务接口 -->
<dubbo:service interface="com.alibaba.dubbo.demo.DemoService"ref="demoService"/>
<!-- 和本地bean一样实现服务 -->
<beanid="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>
服务消费者
<!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->
<dubbo:application name="project_name"/>
<!-- 使用zookeeper广播注册中心暴露服务地址 -->
<dubbo:registry id="registry" protocol="zookeeper" address="224.5.6.7:1234"/>
<!-- 生成远程服务代理,可以和本地bean一样使用demoService -->
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.DemoService"/> 点对点直连
<!-- 直接在服务消费者端配 服务提供者URL -->
<dubbo:reference id="demoService" interface="com.alibaba.dubbo.demo.DemoService" url="dubbo://localhost:20890" />
多注册中心
<!-- 多个地址用 , 隔开 default为false时不向该注册中心注册服务 -->
<dubbo:registry id="dev" address="10.20.141.150:9090,10.20.141.150:8090,10.20.141.150:8090"/>
<dubbo:registry id="test" address="10.20.141.151:9010" default="false"/>
<!-- 向多个注册中心注册 不配registry默认向所有注册中心注册服务 -->
<dubbo:service interface="com.alibaba.hello.HelloService" version="1.0.0" ref="helloService" registry="dev,test"/>
多协议
<dubbo:protocol name="dubbo" port="20880"/>
<dubbo:protocol name="hessian" port="8080"/>
<!-- 使用多个协议暴露服务 -->
<dubbo:service id="helloService" interface="com.alibaba.hello.HelloService" version="1.0.0" protocol="dubbo,hessian"/>服务分组
当一个接口多个实现时可以使用group<!-- 服务者配置 -->
<dubbo:service group="feedback" interface="com.xxx.IndexService"/>
<dubbo:service group="member" interface="com.xxx.IndexService"/>
<!-- 消费者配置 -->
<dubbo:reference id="feedbackIndexService" group="feedback" interface="com.xxx.IndexService"/>
<dubbo:reference id="memberIndexService" group="member" interface="com.xxx.IndexService"/>
多版本
当一个接口实现,出现不兼容升级时,可以用版本号过渡,版本号不同的服务相互间不引用。
在低压力时间段,先升级一半提供者为新版本
再将所有消费者升级为新版本
然后将剩下的一半提供者升级为新版本
<!-- 服务者配置 -->
<dubbo:service interface="com.foo.BarService" version="1.0.0"/>
<dubbo:service interface="com.foo.BarService" version="2.0.0"/>
<!-- 消费者配置 -->
<dubbo:reference id="barService"interface="com.foo.BarService" version="1.0.0"/>
<dubbo:reference id="barService"interface="com.foo.BarService" version="2.0.0"/>
<!-- 不区分版本:(2.2.0以上版本支持) -->
<dubbo:reference id="barService"interface="com.foo.BarService" version="*"/>
令牌验证
防止消费者绕过注册中心访问提供者在注册中心控制权限,以决定要不要下发令牌给消费者
注册中心可灵活改变授权方式,而不需修改或升级提供者
可以全局设置开启令牌验证:
<!--随机token令牌,使用UUID生成-->
<dubbo:provider interface="com.foo.BarService" token="true"/>
<!--固定token令牌,相当于密码-->
<dubbo:provider interface="com.foo.BarService" token="123456"/>也可在服务级别设置:
<!--随机token令牌,使用UUID生成-->
<dubbo:service interface="com.foo.BarService" token="true"/>
<!--固定token令牌,相当于密码-->
<dubbo:service interface="com.foo.BarService" token="123456"/>还可在协议级别设置:
<!--随机token令牌,使用UUID生成-->
<dubbo:protocol name="dubbo" token="true"/>
<!--固定token令牌,相当于密码-->
<dubbo:protocol name="dubbo" token="123456"/>异步调用
基于NIO的非阻塞实现并行调用,客户端不需要启动多线程即可完成并行调用多个远程服务,相对多线程开销较小。
2.0.6及其以上版本支持
配置声明:
<dubbo:referenceid="fooService"interface="com.alibaba.foo.FooService">
<dubbo:methodname="findFoo"async="true"/>
</dubbo:reference> 启动时检查
可以通过check="false"关闭检查,比如,测试时,有些服务不关心,或者出现了循环依赖,必须有一方先启动。
关闭某个服务的启动时检查:(没有提供者时报错)
<dubbo:reference interface="com.foo.BarService" check="false"/>
关闭所有服务的启动时检查:(没有提供者时报错)
<dubbo:consumer check="false"/>
关闭注册中心启动时检查:(注册订阅失败时报错)
<dubbo:registry check="false"/>
887



被折叠的 条评论
为什么被折叠?



