多協議

在 Dubbo 中配置多協定

功能說明

Dubbo 允許多協定配置,支援不同服務上使用不同協定,或是在同一個服務上同時支援多個協定。

使用場景

使用方法

不同服務使用不同協定

不同服務根據效能採用不同的協定進行傳輸。例如,大資料量使用短連線協定,小資料量高併發使用長連線協定。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="https://dubbo.dev.org.tw/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd https://dubbo.dev.org.tw/schema /dubbo https://dubbo.dev.org.tw/schema/dubbo/dubbo.xsd">
    <dubbo:application name="world" />
    <dubbo:registry id="registry" address="10.20.141.150:9090" username="admin" password="hello1234" />
    <!-- Multi-protocol configuration -->
    <dubbo:protocol name="dubbo" port="20880" />
    <dubbo:protocol name="rmi" port="1099" />
    <!-- Use dubbo protocol to expose services -->
    <dubbo:service interface="com.alibaba.hello.api.HelloService" version="1.0.0" ref="helloService" protocol="dubbo" />
    <!-- Use rmi protocol to expose services -->
    <dubbo:service interface="com.alibaba.hello.api.DemoService" version="1.0.0" ref="demoService" protocol="rmi" />
</beans>

多協定暴露服務

需要與 http 客戶端互通

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dubbo="https://dubbo.dev.org.tw/schema/dubbo"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.3.xsd https://dubbo.dev.org.tw/schema /dubbo https://dubbo.dev.org.tw/schema/dubbo/dubbo.xsd">
    <dubbo:application name="world" />
    <dubbo:registry id="registry" address="10.20.141.150:9090" username="admin" password="hello1234" />
    <!-- Multi-protocol configuration -->
    <dubbo:protocol name="dubbo" port="20880" />
    <dubbo:protocol name="hessian" port="8080" />
    <!-- Exposing services using multiple protocols -->
    <dubbo:service id="helloService" interface="com.alibaba.hello.api.HelloService" version="1.0.0" protocol="dubbo,hessian" />
</beans>

上次修改時間:2023 年 1 月 2 日:增強英文文件 (#1798) (95a9f4f6c1c)