信息交换扩展

扩展说明

基于传输层之上,实现 Request-Response 信息交换语义。

扩展接口

  • org.apache.dubbo.remoting.exchange.Exchanger
  • org.apache.dubbo.remoting.exchange.ExchangeServer
  • org.apache.dubbo.remoting.exchange.ExchangeClient

扩展配置

  1. <dubbo:protocol exchanger="xxx" />
  2. <!-- 缺省值设置,当<dubbo:protocol>没有配置exchanger属性时,使用此配置 -->
  3. <dubbo:provider exchanger="xxx" />

已知扩展

org.apache.dubbo.remoting.exchange.exchanger.HeaderExchanger

扩展示例

Maven 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxExchanger.java (实现Exchanger接口)
  7. |-XxxExchangeServer.java (实现ExchangeServer接口)
  8. |-XxxExchangeClient.java (实现ExchangeClient接口)
  9. |-resources
  10. |-META-INF
  11. |-dubbo
  12. |-org.apache.dubbo.remoting.exchange.Exchanger (纯文本文件,内容为:xxx=com.xxx.XxxExchanger)

XxxExchanger.java:

  1. package com.xxx;
  2. import org.apache.dubbo.remoting.exchange.Exchanger;
  3. public class XxxExchanger implements Exchanger {
  4. public ExchangeServer bind(URL url, ExchangeHandler handler) throws RemotingException {
  5. return new XxxExchangeServer(url, handler);
  6. }
  7. public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
  8. return new XxxExchangeClient(url, handler);
  9. }
  10. }

XxxExchangeServer.java:

  1. package com.xxx;
  2. import org.apache.dubbo.remoting.exchange.ExchangeServer;
  3. public class XxxExchangeServer impelements ExchangeServer {
  4. // ...
  5. }

XxxExchangeClient.java:

  1. package com.xxx;
  2. import org.apache.dubbo.remoting.exchange.ExchangeClient;
  3. public class XxxExchangeClient impelments ExchangeClient {
  4. // ...
  5. }

META-INF/dubbo/org.apache.dubbo.remoting.exchange.Exchanger:

  1. xxx=com.xxx.XxxExchanger