dubbo异步调用

dubbo的rpc服务如果使用的是长连接的协议,如dubbo协议,tcp长连接本身是双向异步的,dubbo内部通过监听返回结果,来实现方法调用的同步,所以性能上是有牺牲的。

 

例子:

consumer.xmls

 

<beanid="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:methodname="get"async="true"onreturn="demoCallback.onreturn"onthrow="demoCallback.onthrow"/>
</ dubbo:reference>

 

 

 

 

class NofifyImpl implements Nofify {
public Map<Integer, Person> ret =newHashMap<Integer, Person>();
public Map<Integer, Throwable> errors =newHashMap<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) {//第一个参数为异常,第二个开始参数为入参,异常只有在onreturn的时候发生发生异常(返回异常,这里onreturn调用也是异常的),才调用,
errors.put(id, ex);
}
}


主要关联的几个类,FutureFilter, AbstractInvoker, DubboInvoker

 

最后欢迎大家访问我的个人网站:1024s

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值