Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
武汉红喜
whatsmars
提交
d2910940
W
whatsmars
项目概览
武汉红喜
/
whatsmars
通知
3
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
whatsmars
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d2910940
编写于
11月 01, 2018
作者:
武汉红喜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Dubbo Guide
上级
ac583897
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
13 addition
and
3 deletion
+13
-3
whatsmars-dubbo/README.md
whatsmars-dubbo/README.md
+10
-1
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
...rc/main/resources/META-INF/spring/dubbo-demo-consumer.xml
+2
-1
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
...rc/main/resources/META-INF/spring/dubbo-demo-provider.xml
+1
-1
未找到文件。
whatsmars-dubbo/README.md
浏览文件 @
d2910940
...
...
@@ -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 秒暴露服务 -->
...
...
whatsmars-dubbo/whatsmars-dubbo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml
浏览文件 @
d2910940
...
...
@@ -12,12 +12,13 @@
<!--<!– 使用zookeeper注册中心暴露服务地址 –>-->
<!--<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"
/>
...
...
whatsmars-dubbo/whatsmars-dubbo-provider/src/main/resources/META-INF/spring/dubbo-demo-provider.xml
浏览文件 @
d2910940
...
...
@@ -14,7 +14,7 @@
<!--<dubbo:application name="whatsmars_provider" />-->
<!--<!– 使用zookeeper注册中心暴露服务地址 –>-->
<!--<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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录