Dubbo[達博市]

Dubbo[達博市]
Dubbo[達博市]
更多義項 ▼ 收起列表 ▲

達博市位於澳大利亞新南威爾斯州西北部,是澳大利亞發展最快的內陸城市,人口38000,面積3321平方公里。全年氣候溫和濕潤,年平均降雨量588毫米,冬天平均氣溫16℃,最低3.8℃;夏天平均31.2℃,最高38℃。地理位置優越,是新南威爾斯州重要的公路、鐵路和空中運輸樞紐。

基本信息

城市名稱

達博市位於澳大利亞新南威爾斯州西北部,是澳大利亞發展最快的內陸城市,人口38000,面積3321平方公里。全年氣候溫和濕潤,年平均降雨量588毫米,冬天平均氣溫16℃,最低3.8℃;夏天平均31.2℃,最高38℃。地理位置優越,是新南威爾斯州重要的公路、鐵路和空中運輸樞紐。

旅遊業是達博經濟的一個重要組成部分。境內旅遊資源豐富,設施也較齊全。這裡是人們去沿海旅遊的一個重要驛站。市內有不少具有地方特色的旅遊景點及歷史文化遺蹟,其中聞名世界的"西部平原動物園"是澳大利亞最大的露天動物園。

農業是達博經濟的支柱產業,為俄勒那地區提供了20%的就業機會;達博的畜牧業發達,是澳大利亞東部最大的畜產銷售中心;達博還是新南威爾斯州俄勒那及遠西地區的醫療服務中心和新南威爾斯州重要的銷售和服務中心,其原料產品和礦產物的出口占整個新南威爾斯州的25%

RPC服務框架

LogoLogo

Dubbo是

阿里巴巴公司開源的一個高性能優秀的服務框架,使得套用可通過高性能的 RPC 實現服務的輸

出和輸入功能,可以和

Spring框架無縫集成。

主要核心部件

Remoting: 網路通信框架,實現了 sync-over-async 和 request-response 訊息機制.

RPC: 一個遠程過程調用的抽象,支持負載均衡、容災和集群功能

Registry: 服務目錄框架用於服務的註冊和服務事件發布和訂閱

工作原理

原理圖原理圖

Provider

暴露服務方稱之為“服務提供者”。

Consumer

調用遠程服務方稱之為“服務消費者”。

Registry

服務註冊與發現的中心目錄服務稱之為“服務註冊中心”。

Monitor

統計服務的調用次數和調用時間的日誌服務稱之為“服務監控中心”。

(1) 連通性:

註冊中心負責服務地址的註冊與查找,相當於目錄服務,服務提供者和消費者只在啟動時與註冊中心互動,註冊中心不轉發請求,壓力較小

監控中心負責統計各服務調用次數,調用時間等,統計先在記憶體匯總後每分鐘一次傳送到監控中心伺服器,並以報表展示

服務提供者向註冊中心註冊其提供的服務,並匯報調用時間到監控中心,此時間不包含網路開銷

服務消費者向註冊中心獲取服務提供者地址列表,並根據負載算法直接調用提供者,同時匯報調用時間到監控中心,此時間包含網路開銷

註冊中心,服務提供者,服務消費者三者之間均為長連線,監控中心除外

註冊中心通過長連線感知服務提供者的存在,服務提供者宕機,註冊中心將立即推送事件通知消費者

註冊中心和監控中心全部宕機,不影響已運行的提供者和消費者,消費者在本地快取了提供者列表

註冊中心和監控中心都是可選的,服務消費者可以直連服務提供者

(2) 健狀性:

監控中心宕掉不影響使用,只是丟失部分採樣數據

資料庫宕掉後,註冊中心仍能通過快取提供服務列表查詢,但不能註冊新服務

註冊中心對等集群,任意一台宕掉後,將自動切換到另一台

註冊中心全部宕掉後,服務提供者和服務消費者仍能通過本地快取通訊

服務提供者無狀態,任意一台宕掉後,不影響使用

服務提供者全部宕掉後,服務消費者套用將無法使用,並無限次重連等待服務提供者恢復

(3) 伸縮性:

註冊中心為對等集群,可動態增加機器部署實例,所有客戶端將自動發現新的註冊中心

服務提供者無狀態,可動態增加機器部署實例,註冊中心將推送新的服務提供者信息給消費者

例子

服務端

定義一個Service Interface:(HelloService.java)

package com.alibaba.hello.api; public interface HelloService { String sayHello(String name); }

接口的實現類:(HelloServiceImpl.java)

package com.alibaba.hello.impl; import com.alibaba.hello.api.HelloService; public class HelloServiceImpl implements HelloService { public String sayHello(String name) { return "Hello " + name; } }

Spring配置:(provider.xml)

<?xml version="1.0" encoding="UTF-8"?> <beans ......> <!-- Application name --> <dubbo:application name="hello-world-app" /> <!-- registry address, used for service to register itself --> <dubbo:registry address="multicast://224.5.6.7:1234" /> <!-- expose this service through dubbo protocol, through port 2 0 8 8 0 --> <dubbo:protocol name="dubbo" port="2 0 8 8 0" /> <!-- which service interface do we expose? --> <dubbo:service interface="com.alibaba.hello.api.HelloService" ref="helloService" /> <!-- designate implementation --> <bean id="helloService" class="com.alibaba.hello.impl.HelloServiceImpl" /> </beans>

測試代碼:(Provider.java)

import org.springframework.context.support.ClassPathXmlApplicationContext; public class Provider { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"provider.xml"}); //啟動成功,監聽連線埠為2 0 8 8 0 System.in.read(); // 按任意鍵退出 } }

客戶端

Spring配置檔案:(consumer.xml)

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns=......> <!-- consumer application name --> <dubbo:application name="consumer-of-helloworld-app" /> <!-- registry address, used for consumer to discover services --> <dubbo:registry address="multicast://224.5.6.7:1234" /> <!-- which service to consume? --> <dubbo:reference id="helloService" interface="com.alibaba.hello.api.HelloService" /> </beans>

客戶端測試代碼:(Consumer.java)

import org.springframework.context.support.ClassPathXmlApplicationContext; import com.alibaba.hello.api.HelloService; public class Consumer { public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"consumer.xml"}); HelloService helloService = (HelloService)context.getBean("helloService"); // get service invocation proxy String hello = helloService.sayHello("world"); // do invoke! System.out.println( hello ); // cool, how are you~ } }
、、

相關詞條

相關搜尋

熱門詞條

聯絡我們