dubbo系列六、SPI扩展Filter隐式传参
一、实现Filter接口
1、消费者过滤器:ConsumerTraceFilter.java
package com.dubbo.demo.Filter; import com.alibaba.dubbo.rpc.*; import java.util.Map;
import java.util.UUID; public class ConsumerTraceFilter implements Filter { @Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
Map<String, String> stringStringMap = invocation.getAttachments();
// 设置参数
stringStringMap.put("patentId","0");
stringStringMap.put("traceId",UUID.randomUUID().toString());
System.out.println("生成tradeId:"+stringStringMap.get("traceId"));
return invoker.invoke(invocation);
}
}
2、生产者过滤器:ProviderTraceFilter.java
package com.dubbo.demo.Filter;
import com.alibaba.dubbo.rpc.*;
import java.util.Map;
public class ProviderTraceFilter implements Filter {
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
Map<String, String> stringStringMap = invocation.getAttachments();
// 接收参数
System.out.println("收到:patentId:"+stringStringMap.get("patentId"));
System.out.println("收到:tradeId:"+stringStringMap.get("traceId"));
return invoker.invoke(invocation);
}
}
二、配置SPI Filter扩展文件
1、生产者配置
在目录:resources/META-INF/dubbo/ 创建com.alibaba.dubbo.rpc.Filter(纯文本文件.txt)
内容:
traceFilter=com.dubbo.demo.Filter.ProviderTraceFilter
2、消费者配置
在目录:resources/META-INF/dubbo/ 创建com.alibaba.dubbo.rpc.Filter(纯文本文件.txt)
内容:
traceFilter=com.dubbo.demo.Filter.ConsumerTraceFilter
三、配置dubbo文件
1、生产者
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!--过滤器配置-->
<dubbo:provider filter="traceFilter" />
<!--dubbo应用程序命名-->
<dubbo:application name="dubbo-demo-provider"/>
<!--dubbo注册地址-->
<dubbo:registry address="zookeeper://192.168.1.100:2181"/>
<!--dubbo协议地址-->
<dubbo:protocol name="dubbo" port="20880"/>
<!--接口声明-->
<dubbo:service interface="com.dubbo.demo.api.DemoRpcService" ref="demoRpcService"/>
<bean id="demoRpcService" class="com.dubbo.demo.DemoRpcServiceImpl"/>
</beans>
2、消费者
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo
http://code.alibabatech.com/schema/dubbo/dubbo.xsd"> <!--过滤器配置-->
<dubbo:consumer filter="traceFilter" /> <!--dubbo应用程序命名-->
<dubbo:application name="dubbo-demo-provider"/>
<!--dubbo注册地址-->
<dubbo:registry address="zookeeper://192.168.1.100:2181"/>
<!--接口引用-->
<dubbo:reference interface="com.dubbo.demo.api.DemoRpcService" id="demoRpcService"/>
</beans>
四、验证
依次启动生产者、消费者发起远程调用


示例代码:
https://github.com/Star-Lordxing/dubbo-demo
dubbo系列六、SPI扩展Filter隐式传参的更多相关文章
- 从字节码看java中 this 的隐式传参
从字节码看java中 this 隐式传参具体体现(和python中的self如出一辙,但是比python中藏得更深),也发现了 static 与 非 static 方法的区别所在! static与非s ...
- Dubbo系列讲解之扩展点实现原理分析【2万字分享】
Apache Dubbo 是一款微服务开发框架,它提供了 RPC通信 与 微服务治理 两大关键能力.这意味着,使用 Dubbo 开发的微服务,将具备相互之间的远程发现与通信能力, 同时利用 Dubbo ...
- 第一行Kotlin系列(二)Intent隐式显式跳转及向下传值
1.Intent显式跳转页面 val button5 = findViewById<Button>(R.id.mButton5) button5.setOnClickListener { ...
- webservice系统学习笔记9-使用契约优先的方式的一个服务端demo(隐式传Header信息)
服务器端: 1.编写wsdl文件 <?xml version="1.0" encoding="UTF-8" standalone="no&quo ...
- C#进阶系列——WebApi 接口参数不再困惑:传参详解
前言:还记得刚使用WebApi那会儿,被它的传参机制折腾了好久,查阅了半天资料.如今,使用WebApi也有段时间了,今天就记录下API接口传参的一些方式方法,算是一个笔记,也希望能帮初学者少走弯路.本 ...
- 【转】C#进阶系列——WebApi 接口参数不再困惑:传参详解
原文地址:http://www.cnblogs.com/landeanfen/archive/2016/04/06/5337072.html 阅读目录 一.get请求 1.基础类型参数 2.实体作为参 ...
- [转]C#进阶系列——WebApi 接口参数不再困惑:传参详解
本文转自:http://www.cnblogs.com/landeanfen/p/5337072.html#_label1_2 阅读目录 一.get请求 1.基础类型参数 2.实体作为参数 3.数组作 ...
- saltstack系列(六)——zmq扩展(二)
问题 我们已经熟练的掌握了REQ/REP模式,它是一个一对多的模式,一个REP对应多个REQ. 但是现实工作中,我们会遇到这样的难题,一个REP无法满足REQ的提问,因为REQ太多了,虽然可以增加一个 ...
- Swift实战-豆瓣电台(六)视图跳转,传参及回跳
youku观看地址:http://v.youku.com/v_show/id_XNzMxMzQ3MDcy.html 要点 在ChannelController里面声明一个代理 这个代理遵循我们自定义的 ...
随机推荐
- STM32外设地址查询
问题的提出 DMA传输SDIO驱动的SD卡的数据,其中外设地址的确定 问题的解决 打开数据参考手册,在存储器和总线架构一章存储器映像小节,有一个寄存器组起始地址表,列举所有外设对应的起始地址,再到相应 ...
- 【转】Context Switches上下文切换性能详解
http://blog.csdn.net/aiai5251/article/details/50015745 Context Switches 上下文切换,有时也被称为进程切换(process swi ...
- 分数拆分(Fractions Again?!, UVa 10976)
题目链接:https://vjudge.net/problem/UVA-10976 It is easy to see that for every fraction in the form 1k(k ...
- 【codevs1004】四子连棋 状压bfs
题目大意:给定一个大小为 4*4 的棋盘,分别有 7 个黑子.7 个白子和 2 个空位构成,求出至少需要移动多少步,才能使得四个相同的棋子共线. 题解:显然每一种棋盘的局面都是一个状态,因此需要采用状 ...
- js之string操作符
1.字符方法 // 输出索引值的字符 'zhangamie'.charAt(2) // "a" 'zhangamie'[2] //"a" // 输出编码 a的a ...
- 怎么简单高效破解MyEclipse10、获取注册码
亲测有效 附上地址:https://www.cnblogs.com/caohuimingfa/p/6659902.html
- ibatis (mybatis) for循环拼接语句【转】
使用 , 拼接 查询条件dto public class queryCondition{ private String[] stuIds; private String name;} 查询sqlMap ...
- Hibernate SQL查询 addScalar()或addEntity()【转】
本文完全引用自: http://www.cnblogs.com/chenyixue/p/5601285.html Hibernate除了支持HQL查询外,还支持原生SQL查询. 对原 ...
- scipy笔记—scipy.misc.imresize用法(方便训练图像数据)
scipy.misc.imresize 不同于普通的reshape, imresize不是单纯的改变图像矩阵的维度,而是能将图片重采样为指定像素,这样给深度学习中训练图像数据带来方便. import ...
- webuploader 百度上传,一个页面多个上传按钮
需求:列表里每条数据需加文件上传 html: <div> <ul class="SR_wrap_pic"></ul> <button ty ...