提交 d2910940 编写于 作者: 武汉红喜's avatar 武汉红喜

Dubbo Guide

上级 ac583897
......@@ -87,7 +87,16 @@ RpcContext 的状态都会变化。比如:A 调 B,B 再调 C,则 B 机器
RpcContext.getContext().setAttachment("index", "1");
xxxService.xxx(); // 远程调用
```
- 本地伪装:<dubbo:service interface="com.foo.BarService" mock="com.foo.BarServiceMock" />
- 本地伪装,通常用于降级:<dubbo:service interface="com.foo.BarService" mock="com.foo.BarServiceMock" />
<br>如果服务的消费方经常需要 try-catch 捕获异常,请考虑改为 Mock 实现,并在 Mock 实现中 return null。
如果只是想简单的忽略异常,用mock="return null"即可
- 服务降级,向注册中心写入动态配置覆盖规则:
```java
RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();
Registry registry = registryFactory.getRegistry(URL.valueOf("zookeeper://10.20.153.10:2181"));
// mock=force:return+null mock=fail:return+null
registry.register(URL.valueOf("override://0.0.0.0/com.foo.BarService?category=configurators&dynamic=false&application=foo&mock=fail:return+null"));
```
- 延迟暴露
```xml
<!-- 延迟 5 秒暴露服务 -->
......
......@@ -12,12 +12,13 @@
<!--&lt;!&ndash; 使用zookeeper注册中心暴露服务地址 &ndash;&gt;-->
<!--<dubbo:registry address="zookeeper://127.0.0.1:2181" />-->
<dubbo:reference id="demoService" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" />
<dubbo:reference id="demoService" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" mock="return null" />
<!-- url="hessian://127.0.0.1:8080/org.hongxi.whatsmars.dubbo.demo.api.DemoService" -->
<dubbo:reference id="demoService2" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService"
url="hessian://127.0.0.1:8080" />
<!--protocol默认dubbo,可指定,如果provider没有以该protocol发布,consumer启动会报 No provider-->
<dubbo:reference id="demoService3" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" protocol="hessian" />
<dubbo:reference id="demoService4" group="new" interface="org.hongxi.whatsmars.dubbo.demo.api.DemoService" />
......
......@@ -14,7 +14,7 @@
<!--<dubbo:application name="whatsmars_provider" />-->
<!--&lt;!&ndash; 使用zookeeper注册中心暴露服务地址 &ndash;&gt;-->
<!--<dubbo:registry address="zookeeper://127.0.0.1:2181" />-->
<!-- 多协议配置 -->
<!-- 多协议配置,一种协议只能对应一种序列化方式,建议用hessian2序列化(也是官方推荐,处于稳定性和性能的折中考虑)-->
<dubbo:protocol name="dubbo" port="20880" server="netty4" serialization="fst" />
<dubbo:protocol name="hessian" port="8080" server="jetty" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册