Dubbo 切面监控 操作实例

消费方切面实例


    <dubbo:reference id="demoService" interface="com.jgq.dubbo_Service.service.IProcessData" >  
    	<!-- 切面监控  Callback 监控输入,与输出 必须与 对象方法一致-->  
    	<dubbo:method name="deal"  <strong>onreturn = "demoCallback.onreturn" onthrow="demoCallback.onthrow" </strong> />
    </dubbo:reference>


<span style="white-space:pre">	</span><!-- 本地 bean -->
    <strong><bean id ="demoCallback" class = "com.jgq.service.impl.NotifyImpl" /></strong>


切面被监控的提供方方法定义:

public <strong>String</strong> deal(<strong>String</strong> data);  


针对方法 切面监控 接口定义: 

package com.jgq.service;


public interface Notify {
	public void onreturn(<strong>String deal, String instr</strong>);
        public void onthrow(Throwable ex, <strong>String instr</strong>);
}

【 注意 : 上面监控接口 Notify 中 onreturn 的第一个参数为 被监控方法deal的返回类型, 后续参数为deal的输入参数类型保存一致 】


切面监控接口实现:

public class NotifyImpl implements Notify {

	public Map<String, String> ret = new HashMap<String, String>();
	public Map<String, Throwable> errors = new HashMap<String, Throwable>();

	public void onreturn(String deal, String instr) {
		System.out.println("切面测试: onreturn:" + deal);
		ret.put(instr, deal);
	}

	public void onthrow(Throwable ex, String instr) {
		System.out.println("切面测试: onthrow:" + ex.getMessage());
		errors.put(instr, ex);
	}
}


场景调用:

        System.out.println( <span style="font-family: Arial, Helvetica, sans-serif;">demoService.deal("Hello[你好],Dubbo!") </span>);  



场景结果数据:

切面测试: onreturn:Finished:Hello[你好],Dubbo! 


Thread-0 demoService : Finished:Hello[你好],Dubbo! 












  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值