Dubbox分散式框架

来源:https://www.cnblogs.com/superbc/archive/2018/12/13/10117197.html
-Advertisement-
Play Games

一:簡介:前身是阿裡巴巴的一個開源的項目,後來停止維護,由噹噹網繼續維護,它致力於rpc遠程的調度方案.是一個服務框架 二:執行原理圖: 節點角色說明: · Provider: 暴露服務的服務提供方。 · Consumer: 調用遠程服務的服務消費方。 · Registry: 服務註冊與發現的註冊中 ...


一:簡介:前身是阿裡巴巴的一個開源的項目,後來停止維護,由噹噹網繼續維護,它致力於rpc遠程的調度方案.是一個服務框架

二:執行原理圖:

 

 

節點角色說明:

· Provider: 暴露服務的服務提供方。

· Consumer: 調用遠程服務的服務消費方。

· Registry: 服務註冊與發現的註冊中心。

· Monitor: 統計服務的調用次調和調用時間的監控中心。

· Container: 服務運行容器。

 

調用關係說明:

 

· 0. 服務容器負責啟動,載入,運行服務提供者。

 

· 1. 服務提供者在啟動時,向註冊中心註冊自己提供的服務。

 

· 2. 服務消費者在啟動時,向註冊中心訂閱自己所需的服務。

 

· 3. 註冊中心返回服務提供者地址列表給消費者,如果有變更,註冊中心將基於長連接推

 

送變更數據給消費者。

 

· 4. 服務消費者,從提供者地址列表中,基於軟負載均衡演算法,選一臺提供者進行調用,

 

如果調用失敗,再選另一臺調用。

 

· 5. 服務消費者和提供者,在記憶體中累計調用次數和調用時間,定時每分鐘發送一次統計

 

數據到監控中心。

三:使用

1.建議使用zookper註冊中心(zookper是Apacahe 的子項目)安裝到linux系統上

2.Dubbox本地jar包部署,maven中央倉庫沒有需要手動安裝

 

先將dubbo-2.8.4.jar包放到d:\setup, 然後輸入命令(jar包自行下載)

 

mvn install:install-file -Dfile=d:\setup\dubbo-2.8.4.jar -DgroupId=com.alibaba -DartifactId=dubbo -Dversion=2.8.4 -Dpackaging=jar

3.入門demo

  1.服務提供者,創建Maven工程(WARdubboxdemo-service  ,在pom.xml中引入依賴

 

<properties>

 

<spring.version>4.2.4.RELEASE</spring.version>

 

   </properties>    

 

<dependencies>

 

<!-- Spring 相關 -->

 

<dependency>

 

  <groupId>org.springframework</groupId>

 

  <artifactId>spring-context</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

<dependency>

 

   <groupId>org.springframework</groupId>

 

  <artifactId>spring-beans</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

<dependency>

 

  <groupId>org.springframework</groupId>

 

  <artifactId>spring-webmvc</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

<dependency>

 

  <groupId>org.springframework</groupId>

 

  <artifactId>spring-jdbc</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

<dependency>

 

  <groupId>org.springframework</groupId>

 

  <artifactId>spring-aspects</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

<dependency>

 

  <groupId>org.springframework</groupId>

 

  <artifactId>spring-jms</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

<dependency>

 

  <groupId>org.springframework</groupId>

 

  <artifactId>spring-context-support</artifactId>

 

  <version>${spring.version}</version>

 

</dependency>

 

 

<!-- dubbo相關 -->

 

<dependency>

 

  <groupId>com.alibaba</groupId>

 

  artifactId>dubbo</artifactId>

 

  <version>2.8.4</version>

 

</dependency>

 

<dependency>

 

  <groupId>org.apache.zookeeper</groupId>

 

  <artifactId>zookeeper</artifactId>

 

  <version>3.4.6</version>

 

</dependency>

 

<dependency>

 

  <groupId>com.github.sgroschupf</groupId>

 

  <artifactId>zkclient</artifactId>

 

  <version>0.1</version>

 

</dependency>

 

<dependency>

 

  <groupId>javassist</groupId>

 

  <artifactId>javassist</artifactId>

 

  <version>3.11.0.GA</version>

 

</dependency>

2)在工程的webapps下創建WEB-INF文件夾,創建web.xml

<!-- 載入spring容器 -->

<context-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>classpath:applicationContext*.xml</param-value>

</context-param>

  <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

</listener>

3)創建業務介面

創建包cn.itcast.dubbodemo.service,用於存放業務介面,創建介面

4)創建業務實現類

創建包cn.itcast.dubbodemo.service.impl ,用於存放業務實現類。創建業務實現類:

 

 註意:Service註解與原來不同,需要引入com.alibaba包下的

 

5)編寫配置文件

src/main/resources下創建applicationContext-service.xml ,內容如下:

 

<?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:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

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

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

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

     

<dubbo:application name="dubboxdemo-service"/>  

<dubbo:registry address="zookeeper://192.168.25.132:2181"/><!--虛擬機上的ip-->

<dubbo:annotation package="cn.itcast.dubboxdemo.service" />

</beans>

 

 

 註意:dubbo:annotation用於掃描@Service註解

2.服務消費者開發

創建Maven工程(WARdubboxdemo-web ,在pom.xml引入依賴 ,同“dubboxdemo-service”工程

 

2)在webapps目錄下創建WEB-INF 目錄,並創建web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://java.sun.com/xml/ns/javaee"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

version="2.5">

   <!-- 解決post亂碼 -->

<filter>

<filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>utf-8</param-value>

</init-param>

<init-param>  

            <param-name>forceEncoding</param-name>  

            <param-value>true</param-value>  

        </init-param>  

</filter>

<filter-mapping>

<filter-name>CharacterEncodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

  <servlet>

   <servlet-name>springmvc</servlet-name>   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

   <!-- 指定載入的配置文件 ,通過參數contextConfigLocation載入-->

   <init-param>

   <param-name>contextConfigLocation</param-name>

   <param-value>classpath:applicationContext-web.xml</param-value>

   </init-param>

  </servlet>  

  <servlet-mapping>

   <servlet-name>springmvc</servlet-name>

   <url-pattern>*.do</url-pattern>

  </servlet-mapping>

</web-app>

 

 

 3)拷貝業務介面

 

dubboxdemo-service”工程的cn.itcast.dubboxdemo.service 包以及下麵的介面拷貝至此工程。

 

 4)編寫Controller

5)編寫spring配置文件

src/main/resources下創建applicationContext-web.xml  

 

<?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:p="http://www.springframework.org/schema/p"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

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

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

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

 

<mvc:annotation-driven >

<mvc:message-converters register-defaults="false">

<bean class="org.springframework.http.converter.StringHttpMessageConverter">  

<constructor-arg value="UTF-8" />

</bean>  

</mvc:message-converters>

</mvc:annotation-driven>

<!-- 引用dubbo 服務 -->

<dubbo:application name="dubboxdemo-web" />

<dubbo:registry address="zookeeper://192.168.25.132:2181"/>

     <dubbo:annotation package="cn.itcast.dubboxdemo.controller" />

</beans>

 

 

接下來測試運行

3.6管理中心的部署(百度一下看看怎麼使用安裝部署)

 

 

 

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 在 WEB 項目中返回 JSON 數據是常見的交互形式,在 Spring Boot 中這一切都變得十分簡單。So easy!!! 你所需具備的基礎 "什麼是 Spring Boot?" "Spring Boot 核心配置文件詳解" "Spring Boot 開啟的 2 種方式" "Spring Bo ...
  • 簡介 從今天開始,我們嘗試用2篇博客的內容量,搞定一個網站叫做“美空網”網址為:http://www.moko.cc/, 這個網站我分析了一下,我們要爬取的圖片在 下麵這個網址 http://www.moko.cc/post/1302075.html 然後在去分析一下,我需要找到一個圖片列表頁面是最 ...
  • Python 中可以讀取 word 文件的庫有 python-docx 和 pywin32。 pywin32 這個庫很強大,不僅僅可以讀取 word,但是網上介紹用 pywin32 讀取 .doc 的文章真不多,因為,真心不好用。 以下是 pywin32 讀取 .doc 的代碼示例,但是讀取表格有問 ...
  • 在我刻板的印象里,西游記里的那段孫悟空和二郎神的精彩對戰就能很好的解釋“多態”這個詞:一個孫悟空,能七十二變;一個二郎神,也能七十二變;他們都可以變成不同的形態,但只需要悄悄地喊一聲“變”。 ...
  • 題目內容: 設計一個表示分數的類Fraction。這個類用兩個int類型的變數分別表示分子和分母。 這個類的構造函數是: Fraction(int a, int b) 構造一個a/b的分數。 這個類要提供以下的功能: double toDouble(); 將分數轉換為double Fraction ...
  • Onenet控制繼電器教程 Onenet控制繼電器教程 本文基於STM32物聯網開發版:https://item.taobao.com/item.htm?spm=a1z38n.10677092.0.0.29e71debNLqzWg&id=583890254748 12-18日有大額優惠券哦!!! 內 ...
  • 一 簡介:Spring Security是一個能夠為基於Spring的企業應用系統提供聲明式的安全訪問控制解決方案的安全框架。它提供了一組可以在Spring應用上下文中配置的Bean,充分利用了Spring IoC,DI(控制反轉Inversion of Control ,DI:Dependency ...
  • MyBatis開發原始Dao層請閱讀我的上一篇博客:MyBatis開發Dao層的兩種方式(原始Dao層開發) 接上一篇博客繼續介紹MyBatis開發Dao層的第二種方式:Mapper動態代理方式 Mapper介面開發方法只需要程式員編寫Mapper介面(相當於Dao介面),由Mybatis框架根據接 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...