Dubbo3 信息交換擴(kuò)展

2022-04-22 11:54 更新

擴(kuò)展說(shuō)明

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

擴(kuò)展接口

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

擴(kuò)展配置

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

已知擴(kuò)展

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

擴(kuò)展示例

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

src
 |-main
    |-java
        |-com
            |-xxx
                |-XxxExchanger.java (實(shí)現(xiàn)Exchanger接口)
                |-XxxExchangeServer.java (實(shí)現(xiàn)ExchangeServer接口)
                |-XxxExchangeClient.java (實(shí)現(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)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)