Dubbo各類協議

協議參考手冊

 

(+) (#)html

推薦使用Dubbo協議
性能測試報告
各協議的性能狀況,請參見:性能測試報告 (+)

dubbo://

(+) (#)java

Dubbo缺省協議採用單一長鏈接和NIO異步通信,適合於小數據量大併發的服務調用,以及服務消費者機器數遠大於服務提供者機器數的狀況。
Dubbo缺省協議不適合傳送大數據量的服務,好比傳文件,傳視頻等,除非請求量很低。

 

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


 

Set default protocol:git

 

[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交互。github

  • 鏈接個數:單鏈接
  • 鏈接方式:長鏈接
  • 傳輸協議:TCP
  • 傳輸方式:NIO異步傳輸
  • 序列化:Hessian二進制序列化
  • 適用範圍:傳入傳出參數數據包較小(建議小於100K),消費者比提供者個數多,單一消費者沒法壓滿提供者,儘可能不要用dubbo協議傳輸大文件或超大字符串。
  • 適用場景:常規遠程服務方法調用

爲何要消費者比提供者個數多:
因dubbo協議採用單一長鏈接,
假設網絡爲千兆網卡(1024Mbit=128MByte),
根據測試經驗數據每條鏈接最多隻能壓滿7MByte(不一樣的環境可能不同,供參考),
理論上1個服務提供者須要20個服務消費者才能壓滿網卡。web

爲何不能傳大包:
因dubbo協議採用單一長鏈接,
若是每次請求的數據包大小爲500KByte,假設網絡爲千兆網卡(1024Mbit=128MByte),每條鏈接最大7MByte(不一樣的環境可能不同,供參考),
單個服務提供者的TPS(每秒處理事務數)最大爲:128MByte / 500KByte = 262。
單個消費者調用單個服務提供者的TPS(每秒處理事務數)最大爲:7MByte / 500KByte = 14。
若是能接受,能夠考慮使用,不然網絡將成爲瓶頸。redis

爲何採用異步單一長鏈接:
由於服務的現狀大都是服務提供者少,一般只有幾臺機器,
而服務的消費者多,可能整個網站都在訪問該服務,
好比Morgan的提供者只有6臺提供者,卻有上百臺消費者,天天有1.5億次調用,
若是採用常規的hessian服務,服務提供者很容易就被壓跨,
經過單一鏈接,保證單一消費者不會壓死提供者,
長鏈接,減小鏈接握手驗證等,
並使用異步IO,複用線程池,防止C10K問題。spring

(1) 約束:apache

  • 參數及返回值需實現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 不相同  正常傳輸 

    總結:會拋異常的狀況:枚 舉值一邊多一種,一邊少一種,正好使用了差異的那種,或者屬性名相同,類型不一樣json

接口增長方法,對客戶端無影響,若是該方法不是客戶端須要的,客戶端不須要從新部署;
輸入參數和結果集中增長屬性,對客戶端無影響,若是客戶端並不須要新屬性,不用從新部署;
輸入參數和結果集屬性名變化,對客戶端序列化無影響,可是若是客戶端不從新部署,無論輸入仍是輸出,屬性名變化的屬性值是獲取不到的。
總結:服務器端和客戶端對領域對象並不須要徹底一致,而是按照最大匹配原則。瀏覽器

(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-simpletransports-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"/>  

 參考連接:http://blog.csdn.net/tanga842428/article/details/52717217

                   https://blog.csdn.net/fuyuwei2015/article/details/72848310

相關文章
相關標籤/搜索