Dubbo事件通知
来源:互联网 发布:小白源码 编辑:程序博客网 时间:2024/05/16 00:38
原文地址:http://dubbo.io/User+Guide-zh.htm#UserGuide-zh-事件通知
(3) 服务提供者配置:
注:
callback与async功能正交分解:
async=true,表示结果是否马上返回.
onreturn 表示是否需要回调.
事件通知
(1) 服务提供者与消费者共享服务接口:
interface IDemoService { public Person get(int id);}
(2) 服务提供者实现:
class NormalDemoService implements IDemoService { public Person get(int id) { return new Person(id, "charles`son",4); }}
(3) 服务提供者配置:
provider.xml
<dubbo:application name="rpc-callback-demo"/><dubbo:registry address="http://10.20.160.198/wiki/display/dubbo/10.20.153.186"/><bean id="demoService" class="com.alibaba.dubbo.callback.implicit.NormalDemoService"/><dubbo:service interface="com.alibaba.dubbo.callback.implicit.IDemoService"ref="demoService" version="1.0.0"group="cn"/>
(4) 服务消费者Callback接口及实现:
interface Nofify { public void onreturn(Person msg, Integer id); public void onthrow(Throwable ex, Integer id);}
class NofifyImpl implements Nofify { public Map<Integer, Person> ret = new HashMap<Integer, Person>(); public Map<Integer, Throwable> errors = new HashMap<Integer, Throwable>(); public void onreturn(Person msg, Integer id) { System.out.println("onreturn:" + msg); ret.put(id, msg); } public void onthrow(Throwable ex, Integer id) { errors.put(id, ex); }}
(5) 服务消费者Callback接口及实现:
consumer.xml
<bean id="demoCallback"class= "com.alibaba.dubbo.callback.implicit.NofifyImpl"/><dubbo:reference id="demoService" interface="com.alibaba.dubbo.callback.implicit.IDemoService" version="1.0.0" group="cn"> <dubbo:method name="get" async="true" onreturn= "demoCallback.onreturn" onthrow="demoCallback.onthrow"/></dubbo:reference>
callback与async功能正交分解:
async=true,表示结果是否马上返回.
onreturn 表示是否需要回调.
组合情况:(async=false 默认)
异步回调模式:async=true onreturn="xxx"
同步回调模式:async=false onreturn="xxx"
异步无回调 :async=true
同步无回调 :async=false
(6) TEST CASE:
IDemoService demoService = (IDemoService) context.getBean("demoService");NofifyImpl notify = (NofifyImpl) context.getBean("demoCallback");int requestId = 2;Person ret = demoService.get(requestId);Assert.assertEquals(null, ret);//for Test:只是用来说明callback正常被调用,业务具体实现自行决定.for(int i = 0; i < 10; i++) { if(!notify.ret.containsKey(requestId)) { Thread.sleep(200); }else{ break; }}Assert.assertEquals(requestId, notify.ret.get(requestId).getId());
0 0
- Dubbo事件通知
- Dubbo事件通知
- 13.dubbo异步调用、本地调用、参数回调、事件通知
- 事件通知
- 系统事件通知 定时器事件通知 用户通知(转)
- 空间焦点事件通知
- 内核事件通知(转载)
- WinLogon事件通知包
- OpenNMS扩展 - 事件通知
- 添加本地通知事件
- Winlogon事件通知包
- WinCE7系统事件通知
- 使用NSNotificationCenter 事件通知
- 设备事件通知
- 事件和通知
- libevent事件通知机制
- 内核事件通知
- WinLogon事件通知包
- uboot的relocation原理详细分析
- 第5周项目4--数制转换
- Recyclerview.getLayoutPosition()问题
- Keepalived+MySQL主主数据同步实现数据库高可用(HA)
- Codevs3567 宫廷守卫
- Dubbo事件通知
- HDU 2602 Bone Collector 01背包(裸) .
- JZOJ4800. 周末晚会
- stm 64位整数加减乘除时须注意的一点
- 二维码扫描及简单二维码生成
- java SAX解析XML文件
- SQL Server 数据库 学习笔记
- 04 过程抽象和返回一个值的函数---小结
- Android GridView之添加分隔线,动态设置高度,实现高度自适应,并解决第一个item不显示的问题