Dubbo3 信息交換擴展

2022-04-22 11:54 更新

擴展說明

基于傳輸層之上,實現(xiàn) Request-Response 信息交換語義。

擴展接口

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

擴展配置

<dubbo:protocol exchanger="xxx" />
<!-- 缺省值設(shè)置,當<dubbo:protocol>沒有配置exchanger屬性時,使用此配置 -->
<dubbo:provider exchanger="xxx" />

已知擴展

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

擴展示例

Maven 項目結(jié)構(gòu):

src
 |-main
    |-java
        |-com
            |-xxx
                |-XxxExchanger.java (實現(xiàn)Exchanger接口)
                |-XxxExchangeServer.java (實現(xiàn)ExchangeServer接口)
                |-XxxExchangeClient.java (實現(xiàn)ExchangeClient接口)
    |-resources
        |-META-INF
            |-dubbo
                |-org.apache.dubbo.remoting.exchange.Exchanger (純文本文件,內(nèi)容為:xxx=com.xxx.XxxExchanger)

XxxExchanger.java:

package com.xxx;
 
import org.apache.dubbo.remoting.exchange.Exchanger;
 
 
public class XxxExchanger implements Exchanger {
    public ExchangeServer bind(URL url, ExchangeHandler handler) throws RemotingException {
        return new XxxExchangeServer(url, handler);
    }
    public ExchangeClient connect(URL url, ExchangeHandler handler) throws RemotingException {
        return new XxxExchangeClient(url, handler);
    }
}

XxxExchangeServer.java:


package com.xxx;
 
import org.apache.dubbo.remoting.exchange.ExchangeServer;
 
public class XxxExchangeServer impelements ExchangeServer {
    // ...
}

XxxExchangeClient.java:

package com.xxx;
 
import org.apache.dubbo.remoting.exchange.ExchangeClient;
 
public class XxxExchangeClient impelments ExchangeClient {
    // ...
}

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

xxx=com.xxx.XxxExchanger


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號