dubbo應用場景示例四

1、多註冊中心

Dubbo 支持同一服務向多註冊中心同時註冊,或者不同服務分別註冊到不同的註冊中心上 去,甚至可以同時引用註冊在不同註冊中心上的同名服務。另外,註冊中心是支持自定義擴展的(可以自行擴展註冊中心)。

1.1、多註冊中心註冊

比如:中文站有些服務來不及在青島部署,只在杭州部署,而青島的其它應用需要引用此服 務,就可以將服務同時註冊到兩個註冊中心。

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http: //code.alibabatech.com/schema/dubbo/dubbo.xsd">

1.2、不同服務使用不同註冊中心

比如:CRM 有些服務是專門為國際站設計的,有些服務是專門為中文站設計的。

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http: //code.alibabatech.com/schema/dubbo/dubbo.xsd">

1.3、多註冊中心引用

比如:CRM 需同時調用中文站和國際站的 PC2 服務,PC2 在中文站和國際站均有部署,接 口及版本號都一樣,但連的數據庫不一樣。

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http: //code.alibabatech.com/schema/dubbo/dubbo.xsd">

如果只是測試環境臨時需要連接兩個不同註冊中心,使用豎號分隔多個不同註冊中心地址:

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://code.alibabatech.com/schema/dubbo

http: //code.alibabatech.com/schema/dubbo/dubbo.xsd">

2、服務分組

當一個接口有多種實現時,可以用 group 區分。

2.1、服務

2.2、引用

任意組(2.2.0 以上版本支持,總是隻調一個可用組的實現)

3、多版本

當一個接口實現,出現不兼容升級時,可以用版本號過渡,版本號不同的服務相互間不引用。

可以按照以下的步驟進行版本遷移:

1. 在低壓力時間段,先升級一半提供者為新版本

2. 再將所有消費者升級為新版本

3. 然後將剩下的一半提供者升級為新版本

老版本服務提供者配置:

新版本服務提供者配置:

老版本服務消費者配置:

新版本服務消費者配置:

如果不需要區分版本,可以按照以下的方式配置(2.2.0 以上版本支持):

dubbo應用場景示例四

dubbo應用場景示例四


分享到:


相關文章: