当前位置: 首页 > news >正文

Dubbo各种协议详解

(1)协议支持

Dubbo支持多种协议,如下所示:

  • Dubbo协议
  • Hessian协议
  • HTTP协议
  • RMI协议
  • WebService协议
  • Thrift协议
  • Memcached协议
  • Redis协议

在通信过程中,不同的服务等级一般对应着不同的服务质量,那么选择合适的协议便是一件非常重要的事情。你可以根据你应用的创建来选择。例如,使用RMI协议,一般会受到防火墙的限制,所以对于外部与内部进行通信的场景,就不要使用RMI协议,而是基于HTTP协议或者Hessian协议。

(2)默认使用Dubbo协议

连接个数:单连接
连接方式:长连接
传输协议:TCP
传输方式:NIO异步传输
序列化:Hessian二进制序列化
适用范围:传入传出参数数据包较小(建议小于100K),消费者比提供者个数多,单一消费者无法压满提供者,尽量不要使用dubbo协议传输大文件或超大字符串
使用场景:常规远程服务方法调用
从上面的适用范围总结,dubbo适合小数据量大并发的服务调用,以及消费者机器远大于生产者机器数的情况,不适合传输大数据量的服务比如文件、视频等,除非请求量很低。

 

协议参考手册

 

(+) (#)

推荐使用Dubbo协议
性能测试报告
各协议的性能情况,请参见:性能测试报告 (+)

dubbo://

(+) (#)

Dubbo缺省协议采用单一长连接和NIO异步通讯,适合于小数据量大并发的服务调用,以及服务消费者机器数远大于服务提供者机器数的情况。
Dubbo缺省协议不适合传送大数据量的服务,比如传文件,传视频等,除非请求量很低。

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="dubbo" port="20880"/>  



 

Set default protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:provider protocol="dubbo"/>  


Set service protocol:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:service protocol="dubbo"/>  

Multi port:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol id="dubbo1" name="dubbo" port="20880"/>  
  2. <dubbo:protocol id="dubbo2" name="dubbo" port="20881"/>  


Dubbo protocol options:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name=“dubbo” port=“9090” server=“netty” client=“netty” codec=“dubbo” serialization=“hessian2” charset=“UTF-8” threadpool=“fixed” threads=“100” queues=“0” iothreads=“9” buffer=“8192” accepts=“1000” payload=“8388608” />  


 

  • Transporter
    • mina, netty, grizzy
  • Serialization
    • dubbo, hessian2, java, json
  • Dispatcher
    • all, direct, message, execution, connection
  • ThreadPool
    • fixed, cached
Dubbo协议缺省每服务每提供者每消费者使用单一长连接,如果数据量较大,可以使用多个连接。
  • [html]  view plain  copy
     
     在CODE上查看代码片派生到我的代码片
    1. <dubbo:protocol name="dubbo"connections="2"/>  


  • <dubbo:service connections=”0”>或<dubbo:reference connections=”0”>表示该服务使用JVM共享长连接。(缺省)
  • <dubbo:service connections=”1”>或<dubbo:reference connections=”1”>表示该服务使用独立长连接。
  • <dubbo:service connections=”2”>或<dubbo:reference connections=”2”>表示该服务使用独立两条长连接。
为防止被大量连接撑挂,可在服务提供方限制大接收连接数,以实现服务提供方自我保护。

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="dubbo" accepts="1000"/>  

 

缺省协议,使用基于mina1.1.7+hessian3.2.1的tbremoting交互。

  • 连接个数:单连接
  • 连接方式:长连接
  • 传输协议:TCP
  • 传输方式:NIO异步传输
  • 序列化:Hessian二进制序列化
  • 适用范围:传入传出参数数据包较小(建议小于100K),消费者比提供者个数多,单一消费者无法压满提供者,尽量不要用dubbo协议传输大文件或超大字符串。
  • 适用场景:常规远程服务方法调用

为什么要消费者比提供者个数多:
因dubbo协议采用单一长连接,
假设网络为千兆网卡(1024Mbit=128MByte),
根据测试经验数据每条连接最多只能压满7MByte(不同的环境可能不一样,供参考),
理论上1个服务提供者需要20个服务消费者才能压满网卡。

为什么不能传大包:
因dubbo协议采用单一长连接,
如果每次请求的数据包大小为500KByte,假设网络为千兆网卡(1024Mbit=128MByte),每条连接最大7MByte(不同的环境可能不一样,供参考),
单个服务提供者的TPS(每秒处理事务数)最大为:128MByte / 500KByte = 262。
单个消费者调用单个服务提供者的TPS(每秒处理事务数)最大为:7MByte / 500KByte = 14。
如果能接受,可以考虑使用,否则网络将成为瓶颈。

为什么采用异步单一长连接:
因为服务的现状大都是服务提供者少,通常只有几台机器,
而服务的消费者多,可能整个网站都在访问该服务,
比如Morgan的提供者只有6台提供者,却有上百台消费者,每天有1.5亿次调用,
如果采用常规的hessian服务,服务提供者很容易就被压跨,
通过单一连接,保证单一消费者不会压死提供者,
长连接,减少连接握手验证等,
并使用异步IO,复用线程池,防止C10K问题。

(1) 约束:

  • 参数及返回值需实现Serializable接口
  • 参数及返回值不能自定义实现List, Map, Number, Date, Calendar等接口,只能用JDK自带的实现,因为hessian会做特殊处理,自定义实现类中的属性值都会丢失。()
  • Hessian序列化,只传成员属性值和值的类型,不传方法或静态变量,兼容情况:(由吴亚军提供)
    数据通讯 情况 结果 
    A->B 类A多一种 属性(或者说类B少一种 属性) 不抛异常,A多的那 个属性的值,B没有, 其他正常 
    A->B 枚举A多一种 枚举(或者说B少一种 枚举),A使用多 出来的枚举进行传输 抛异常 
    A->B 枚举A多一种 枚举(或者说B少一种 枚举),A不使用 多出来的枚举进行传输 不抛异常,B正常接 收数据 
    A->B A和B的属性 名相同,但类型不相同 抛异常 
    A->B serialId 不相同 正常传输 

    总结:会抛异常的情况:枚 举值一边多一种,一边少一种,正好使用了差别的那种,或者属性名相同,类型不同

接口增加方法,对客户端无影响,如果该方法不是客户端需要的,客户端不需要重新部署;
输入参数和结果集中增加属性,对客户端无影响,如果客户端并不需要新属性,不用重新部署;
输入参数和结果集属性名变化,对客户端序列化无影响,但是如果客户端不重新部署,不管输入还是输出,属性名变化的属性值是获取不到的。
总结:服务器端和客户端对领域对象并不需要完全一致,而是按照最大匹配原则。

(2) 配置:
dubbo.properties:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. dubbo.service.protocol=dubbo  

 

rmi://

 

(+) (#)

RMI协议采用JDK标准的java.rmi.*实现,采用阻塞式短连接和JDK标准序列化方式。
如果正在使用RMI提供服务给外部访问(公司内网环境应该不会有攻击风险),同时应用里依赖了老的common-collections包(dubbo不会依赖这个包,请排查自己的应用有没有使用)的情况下,存在反序列化安全风险。
请检查应用:
将commons-collections3 请升级到3.2.2版本:https://commons.apache.org/proper/commons-collections/release_3_2_2.html
将commons-collections4 请升级到4.1版本:https://commons.apache.org/proper/commons-collections/release_4_1.html
新版本的commons-collections解决了该问题
  • 如果服务接口继承了java.rmi.Remote接口,可以和原生RMI互操作,即:
    • 提供者用Dubbo的RMI协议暴露服务,消费者直接用标准RMI接口调用,
    • 或者提供方用标准RMI暴露服务,消费方用Dubbo的RMI协议调用。
  • 如果服务接口没有继承java.rmi.Remote接口,
    • 缺省Dubbo将自动生成一个com.xxx.XxxService$Remote的接口,并继承java.rmi.Remote接口,并以此接口暴露服务,
    • 但如果设置了<dubbo:protocol name="rmi" codec="spring" />,将不生成$Remote接口,而使用Spring的RmiInvocationHandler接口暴露服务,和Spring兼容。

Define rmi protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="rmi"port="1099"/>  


Set default protocol:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:provider protocol="rmi"/>  

 

Set service protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:service protocol="rmi"/>  

 

Multi port:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol id="rmi1" name="rmi" port="1099"/>  
  2. <dubbo:protocol id="rmi2" name="rmi" port="2099"/>  
  3.    
  4. <dubbo:service protocol="rmi1"/>  


Spring compatible:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="rmi" codec="spring"/>  


Java标准的远程调用协议。

 

  • 连接个数:多连接
  • 连接方式:短连接
  • 传输协议:TCP
  • 传输方式:同步传输
  • 序列化:Java标准二进制序列化
  • 适用范围:传入传出参数数据包大小混合,消费者与提供者个数差不多,可传文件。
  • 适用场景:常规远程服务方法调用,与原生RMI服务互操作

(1) 约束:

  • 参数及返回值需实现Serializable接口
  • dubbo配置中的超时时间对rmi无效,需使用java启动参数设置:-Dsun.rmi.transport.tcp.responseTimeout=3000,参见下面的RMI配置。

(2) 配置:
dubbo.properties:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. dubbo.service.protocol=rmi  


(3) RMI配置:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. java -Dsun.rmi.transport.tcp.responseTimeout=3000  


更多RMI优化参数请查看:

 

http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/technotes/guides/rmi/sunrmiproperties.html

hessian://

(+) (#)

Hessian协议用于集成Hessian的服务,Hessian底层采用Http通讯,采用Servlet暴露服务,Dubbo缺省内嵌Jetty作为服务器实现。
Hessian是Caucho开源的一个RPC框架:http://hessian.caucho.com,其通讯效率高于WebService和Java自带的序列化。

依赖:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dependency>  
  2.     <groupId>com.caucho</groupId>  
  3.     <artifactId>hessian</artifactId>  
  4.     <version>4.0.7</version>  
  5. </dependency>  


可以和原生Hessian服务互操作,即:

 

  • 提供者用Dubbo的Hessian协议暴露服务,消费者直接用标准Hessian接口调用,
  • 或者提供方用标准Hessian暴露服务,消费方用Dubbo的Hessian协议调用。

基于Hessian的远程调用协议。

  • 连接个数:多连接
  • 连接方式:短连接
  • 传输协议:HTTP
  • 传输方式:同步传输
  • 序列化:Hessian二进制序列化
  • 适用范围:传入传出参数数据包较大,提供者比消费者个数多,提供者压力较大,可传文件。
  • 适用场景:页面传输,文件传输,或与原生hessian服务互操作

(1) 约束:

  • 参数及返回值需实现Serializable接口
  • 参数及返回值不能自定义实现List, Map, Number, Date, Calendar等接口,只能用JDK自带的实现,因为hessian会做特殊处理,自定义实现类中的属性值都会丢失。

(2) 配置:
Define hessian protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="hessian" port="8080" server="jetty"/>  

 

Set default protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:provider protocol="hessian"/>  

 

Set service protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:service protocol="hessian"/>  


Multi port:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol id="hessian1" name="hessian" port="8080"/>  
  2. <dubbo:protocol id="hessian2" name="hessian" port="8081"/>  

 

Directly provider:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="helloService" interface="HelloWorld" url="hessian://10.20.153.10:8080/helloWorld"/>  


h4. Jetty Server: (default)

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol... server="jetty"/>  


h4. Servlet Bridge Server: (recommend)

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol... server="servlet"/>  

web.xml:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <servlet>  
  2.          <servlet-name>dubbo</servlet-name>  
  3.          <servlet-class>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet</servlet-class>  
  4.          <load-on-startup>1</load-on-startup>  
  5. </servlet>  
  6. <servlet-mapping>  
  7.          <servlet-name>dubbo</servlet-name>  
  8.          <url-pattern>/*</url-pattern>  
  9. </servlet-mapping>  


注意,如果使用servlet派发请求:

 

  • 协议的端口<dubbo:protocol port="8080" />必须与servlet容器的端口相同,
  • 协议的上下文路径<dubbo:protocol contextpath="foo" />必须与servlet应用的上下文路径相同。

http://

(+) (#)

采用Spring的HttpInvoker实现
2.3.0以上版本支持

基于http表单的远程调用协议。参见:[HTTP协议使用说明]

  • 连接个数:多连接
  • 连接方式:短连接
  • 传输协议:HTTP
  • 传输方式:同步传输
  • 序列化:表单序列化
  • 适用范围:传入传出参数数据包大小混合,提供者比消费者个数多,可用浏览器查看,可用表单或URL传入参数,暂不支持传文件。
  • 适用场景:需同时给应用程序和浏览器JS使用的服务。

(1) 约束:

  • 参数及返回值需符合Bean规范

(2) 配置:
dubbo.xml:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="http" port="8080"/>  


h4. Jetty Server: (default)

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol... server="jetty"/>  

h4. Servlet Bridge Server: (recommend)

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol... server="servlet"/>  

web.xml:
[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <servlet>  
  2.          <servlet-name>dubbo</servlet-name>  
  3.          <servlet-class>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet</servlet-class>  
  4.          <load-on-startup>1</load-on-startup>  
  5. </servlet>  
  6. <servlet-mapping>  
  7.          <servlet-name>dubbo</servlet-name>  
  8.          <url-pattern>/*</url-pattern>  
  9. </servlet-mapping>  

注意,如果使用servlet派发请求:
  • 协议的端口<dubbo:protocol port="8080" />必须与servlet容器的端口相同,
  • 协议的上下文路径<dubbo:protocol contextpath="foo" />必须与servlet应用的上下文路径相同。

webservice://

(+) (#)

2.3.0以上版本支持。
基于CXF的frontend-simple和transports-http实现。
CXF是Apache开源的一个RPC框架:http://cxf.apache.org,由Xfire和Celtix合并而来 。

依赖:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dependency>  
  2.     <groupId>org.apache.cxf</groupId>  
  3.     <artifactId>cxf-rt-frontend-simple</artifactId>  
  4.     <version>2.6.1</version>  
  5. </dependency>  
  6. <dependency>  
  7.     <groupId>org.apache.cxf</groupId>  
  8.     <artifactId>cxf-rt-transports-http</artifactId>  
  9.     <version>2.6.1</version>  
  10. </dependency>  


可以和原生WebService服务互操作,即:

 

  • 提供者用Dubbo的WebService协议暴露服务,消费者直接用标准WebService接口调用,
  • 或者提供方用标准WebService暴露服务,消费方用Dubbo的WebService协议调用。

基于WebService的远程调用协议。

  • 连接个数:多连接
  • 连接方式:短连接
  • 传输协议:HTTP
  • 传输方式:同步传输
  • 序列化:SOAP文本序列化
  • 适用场景:系统集成,跨语言调用。

(1) 约束:

  • 参数及返回值需实现Serializable接口
  • 参数尽量使用基本类型和POJO。

(2) 配置:
Define hessian protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="webservice"port="8080"server="jetty"/>  

 

Set default protocol:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:provider protocol="webservice"/>  


Set service protocol:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:service protocol="webservice"/>  


Multi port:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol id="webservice1" name="webservice"port="8080"/>  
  2. <dubbo:protocol id="webservice2" name="webservice"port="8081"/>  

 

Directly provider:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="helloService" interface="HelloWorld" url="webservice://10.20.153.10:8080/com.foo.HelloWorld"/>  


WSDL:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. http://10.20.153.10:8080/com.foo.HelloWorld?wsdl  


h4. Jetty Server: (default)

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol... server="jetty"/>  


h4. Servlet Bridge Server: (recommend)

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. dubbo:protocol... server="servlet"/>  

web.xml:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <servlet>  
  2.          <servlet-name>dubbo</servlet-name>  
  3.          <servlet-class>com.alibaba.dubbo.remoting.http.servlet.DispatcherServlet</servlet-class>  
  4.          <load-on-startup>1</load-on-startup>  
  5. </servlet>  
  6. <servlet-mapping>  
  7.          <servlet-name>dubbo</servlet-name>  
  8.          <url-pattern>/*</url-pattern>  
  9. </servlet-mapping>  


注意,如果使用servlet派发请求:

 

  • 协议的端口<dubbo:protocol port="8080" />必须与servlet容器的端口相同,
  • 协议的上下文路径<dubbo:protocol contextpath="foo" />必须与servlet应用的上下文路径相同。

thrift://

(+) (#)

2.3.0以上版本支持。
Thrift说明
Thrift是Facebook捐给Apache的一个RPC框架,参见:http://thrift.apache.org
dubbo thrift协议
当前 dubbo 支持的 thrift 协议是对 thrift 原生协议的扩展,在原生协议的基础上添加了一些额外的头信息,比如service name,magic number等。使用dubbo thrift协议同样需要使用thrift的idl compiler编译生成相应的java代码,后续版本中会在这方面做一些增强。

示例:https://github.com/alibaba/dubbo/tree/master/dubbo-rpc/dubbo-rpc-thrift/src/test/java/com/alibaba/dubbo/rpc/protocol/thrift/examples

依赖:

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dependency>  
  2.     <groupId>org.apache.thrift</groupId>  
  3.     <artifactId>libthrift</artifactId>  
  4.     <version>0.8.0</version>  
  5. </dependency  


所有服务共用一个端口:(与原生Thrift不兼容)

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:protocol name="thrift"port="3030"/>  


Thrift不支持数据类型:

 

  • null值 (不能在协议中传递null值)

memcached://

(+) (#)

2.3.0以上版本支持。
Memcached说明
Memcached是一个高效的KV缓存服务器,参见:http://memcached.org/

可以通过脚本或监控中心手工填写表单注册memcached服务的地址:

 

[java]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();  
  2. Registry registry = registryFactory.getRegistry(URL.valueOf("zookeeper://10.20.153.10:2181"));  
  3. registry.register(URL.valueOf("memcached://10.20.153.11/com.foo.BarService?category=providers&dynamic=false&application=foo&group=member&loadbalance=consistenthash"));  


然后在客户端使用时,不需要感知Memcached的地址:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="cache" interface="http://10.20.160.198/wiki/display/dubbo/java.util.Map" group="member" />  


或者,点对点直连:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="cache" interface="http://10.20.160.198/wiki/display/dubbo/java.util.Map" url="memcached://10.20.153.10:11211" />  


也可以使用自定义接口:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="cache" interface="com.foo.CacheService" url="memcached://10.20.153.10:11211"/>  

方法名建议和memcached的标准方法名相同,即:get(key), set(key, value), delete(key)。

 

如果方法名和memcached的标准方法名不相同,则需要配置映射关系:(其中"p:xxx"为spring的标准p标签)

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="cache" interface="com.foo.CacheService" url="memcached://10.20.153.10:11211" p:set="putFoo" p:get="getFoo" p:delete="removeFoo"/>  

 

redis://

 

(+) (#)

2.3.0以上版本支持。
Redis说明
Redis是一个高效的KV存储服务器,参见:http://redis.io

可以通过脚本或监控中心手工填写表单注册redis服务的地址:

 

[java]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.class).getAdaptiveExtension();  
  2. Registry registry = registryFactory.getRegistry(URL.valueOf("zookeeper://10.20.153.10:2181"));  
  3. registry.register(URL.valueOf("redis://10.20.153.11/com.foo.BarService?category=providers&dynamic=false&application=foo&group=member&loadbalance=consistenthash"));  


然后在客户端使用时,不需要感知Redis的地址:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="store" interface="http://10.20.160.198/wiki/display/dubbo/java.util.Map" group="member" />  


或者,点对点直连:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="store" interface="http://10.20.160.198/wiki/display/dubbo/java.util.Map" url="redis://10.20.153.10:6379" />  


也可以使用自定义接口:

 

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="store" interface="com.foo.StoreService" url="redis://10.20.153.10:6379"/>  

 

方法名建议和redis的标准方法名相同,即:get(key), set(key, value), delete(key)。

如果方法名和redis的标准方法名不相同,则需要配置映射关系:(其中"p:xxx"为spring的标准p标签)

 

[html]  view plain  copy
 
 在CODE上查看代码片派生到我的代码片
  1. <dubbo:reference id="cache" interface="com.foo.CacheService" url="memcached://10.20.153.10:11211" p:set="putFoo" p:get="getFoo" p:delete="removeFoo"/>  

 

相关文章:

  • Java,console输出实时的转向GUI textbox
  • SpringBoot 日志框架
  • Expression.Bind()方法的应用
  • python基础----特性(property)、静态方法(staticmethod)、类方法(classmethod)、__str__的用法...
  • Extjs 4 grid中的checkbox的加载时预选中【默认选中】
  • java: -source 1.6 中不支持 switch 中存在字符串.....
  • Python中大名鼎鼎的face_recognition使用
  • Spark 触发Job提交
  • 【bzoj1013】[JSOI2008]球形空间产生器sphere
  • 与众不同 windows phone (44) - 8.0 位置和地图
  • 小程序开发之获取小程序二维码
  • Android Contextual Menus之二:contextual action mode
  • 基本类型和引用类型的值 动态的属性
  • JVM启动参数小结
  • java B2B2C源码电子商务平台 -----客户端负载均衡策略
  • 2018天猫双11|这就是阿里云!不止有新技术,更有温暖的社会力量
  • Angularjs之国际化
  • Apache Spark Streaming 使用实例
  • - C#编程大幅提高OUTLOOK的邮件搜索能力!
  • CSS居中完全指南——构建CSS居中决策树
  • es的写入过程
  • iOS仿今日头条、壁纸应用、筛选分类、三方微博、颜色填充等源码
  • java8-模拟hadoop
  • JavaScript 基本功--面试宝典
  • javascript从右向左截取指定位数字符的3种方法
  • LeetCode18.四数之和 JavaScript
  • Netty 4.1 源代码学习:线程模型
  • php ci框架整合银盛支付
  • PHP CLI应用的调试原理
  • SQLServer之创建显式事务
  • supervisor 永不挂掉的进程 安装以及使用
  • VirtualBox 安装过程中出现 Running VMs found 错误的解决过程
  • 程序员最讨厌的9句话,你可有补充?
  • 深入浏览器事件循环的本质
  • 使用 Xcode 的 Target 区分开发和生产环境
  • 微信小程序填坑清单
  • 栈实现走出迷宫(C++)
  • nb
  • No resource identifier found for attribute,RxJava之zip操作符
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • 资深实践篇 | 基于Kubernetes 1.61的Kubernetes Scheduler 调度详解 ...
  • ​业务双活的数据切换思路设计(下)
  • #{}和${}的区别?
  • #git 撤消对文件的更改
  • (C语言)求出1,2,5三个数不同个数组合为100的组合个数
  • (附源码)ssm基于jsp高校选课系统 毕业设计 291627
  • (六)什么是Vite——热更新时vite、webpack做了什么
  • (推荐)叮当——中文语音对话机器人
  • (一)Neo4j下载安装以及初次使用
  • (一)SpringBoot3---尚硅谷总结
  • (转)http协议
  • (转)nsfocus-绿盟科技笔试题目
  • (转载)跟我一起学习VIM - The Life Changing Editor
  • ***通过什么方式***网吧
  • .a文件和.so文件