dubbo教程一
目錄
- 基礎知識:
- 分布式基礎理論:
- zookeeper的安裝:
基礎知識:
分布式基礎理論:
傳統項目開始只有一個服務器:
然后為了高性能和高可用;增加服務器組成服務器集群:
然后現在的大型項目:
總結:
架構的演進:
單體架構:這個可以進行集群部署,即多機器單體架構:
mvc
dubbo概念:
Apache Dubbo是一款高性能、輕量級的開源Java RPC框架,它提供了三大核心功能:
- 面向接口的遠程方法調用
- 智能容錯和負載均衡
- 服務自動注冊和發現
Dubbo的架構:
調用關系說明:
Dubbo的一些特性:
- 面向接口代理的高性能RPC調用:提供高性能的基于代理 遠程調用能力,服務以接口為粒度,為開發者屏蔽遠程調用底層細節
- 智能負載均衡:內置多種負載均衡策略,智能感知下游節點健康狀況,顯著減少調用延遲,提高系統吞吐量。
- 服務自動注冊與發現:支持多種注冊中心服務,服務實例上下游實時感知。
- 高度可擴展能力:遵循微內核+插件的設計原則,所有核心能力如Protocol、Transport、Serialization被設計為擴展點,平等對待內置實現和第三方實現。
- 運行期流量調度:內置條件、腳本等路由策略,通過配置不同的路由規則,輕松實現灰度發布,同機房優先等功能。
- 可視化的服務治理與運維:提供豐富服務治理、運維工具:隨時查詢服務元數據、服務健康狀態及調用統計,實時下發路由策略、調整配置參數。
服務自動注冊和發現:
zookeeper的安裝:
先搭建一個注冊中心:zookeeper的安裝:
官網找教程:
Zookeeper 注冊中心
Zookeeper 注冊中心參考手冊
Zookeeper 是 Apache Hadoop 的子項目,是一個樹型的目錄服務,支持變更推送,適合作為 Dubbo 服務的注冊中心,工業強度較高,可用于生產環境,并推薦使用 。
Zookeeper下載的官網:https://zookeeper.apache.org/
去打下載頁面:
歷史版本下載:
下載一個穩定版的3.4.xx的,也可以下載3.5.6版本
這是linux版本的安裝手冊,linux版本:
Bubbo快速入門:
創建空的項目:
然后file->settings設置maven
然后創建兩個模塊:
第一個模塊:
file->new module
然后:
名字我們叫:dubbo-service
然后第二個模塊:
dubbo-web:
接下來我們為兩個模塊導入相應的pom的jar坐標:
我們使用官方下載的pom:
<?xml version="1.0" encoding="UTF-8"?> <!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the "License"); you may not use this file except in compliance withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.--> <project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><groupId>org.apache.dubbo</groupId><version>1.0-SNAPSHOT</version><modelVersion>4.0.0</modelVersion><artifactId>dubbo-samples-basic</artifactId><properties><source.level>1.8</source.level><target.level>1.8</target.level><dubbo.version>2.7.7</dubbo.version><junit.version>4.12</junit.version><spring.version>4.3.16.RELEASE</spring.version><maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-framework-bom</artifactId><version>${spring.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-bom</artifactId><version>${dubbo.version}</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-dependencies-zookeeper</artifactId><version>${dubbo.version}</version><type>pom</type></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo</artifactId></dependency><dependency><groupId>org.apache.dubbo</groupId><artifactId>dubbo-dependencies-zookeeper</artifactId><type>pom</type></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-test</artifactId><scope>test</scope></dependency></dependencies><profiles><!-- For jdk 11 above JavaEE annotation --><profile><id>javax.annotation</id><activation><jdk>[1.11,)</jdk></activation><dependencies><dependency><groupId>javax.annotation</groupId><artifactId>javax.annotation-api</artifactId><version>1.3.2</version></dependency></dependencies></profile><profile><id>provider</id><build><plugins><plugin><!-- Build an executable JAR --><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><finalName>provider</finalName><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib/</classpathPrefix><mainClass>org.apache.dubbo.samples.basic.BasicProvider</mainClass></manifest></archive></configuration></plugin></plugins></build></profile><profile><id>consumer</id><build><plugins><plugin><!-- Build an executable JAR --><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><configuration><finalName>consumer</finalName><archive><manifest><addClasspath>true</addClasspath><classpathPrefix>lib/</classpathPrefix><mainClass>org.apache.dubbo.samples.basic.BasicConsumer</mainClass></manifest></archive></configuration></plugin></plugins></build></profile></profiles><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven-compiler-plugin.version}</version><configuration><source>${source.level}</source><target>${target.level}</target></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-dependency-plugin</artifactId><executions><execution><id>copy-dependencies</id><phase>prepare-package</phase><goals><goal>copy-dependencies</goal></goals><configuration><outputDirectory>${project.build.directory}/lib</outputDirectory></configuration></execution></executions></plugin></plugins></build> </project>將這個文件放到web和service的pom中;
然后編寫接口和實現類:
然后是實現類:
將web項目導包方式換成war:
<artifactId>dubbo-samples-basic</artifactId><packaging>war</packaging>然后記得刷新右邊的maven:然后在web項目創建目錄:
創建webapp目錄:
內容如下:
依賴一下另一個模塊:
準備dubbo的核心配置文件:
解壓到當前文件夾下即可:
然后進入解壓后的文件夾的bin目錄,發現可執行命令:zkServer.cmd
然后啟動:
輸入啟動命令:zkServer.cmd發現啟動報錯如下:
修改配置文件zoo.cfg,將其修改成 dataDir=…/data
然后我們保存修改,并重新控制臺啟動:zkService.cmd
并看到啟動成功。
然后測試連接zk服務器:使用zkCli.cmd
測試:create -e /fan 123456等等
下載dubbo-admin:
https://github.com/apache/dubbo-admin
注意:需要安裝node.js
下載壓縮包:
然后解壓,并查看配置:
然后確保你的maven是安裝好的:
運行打包好的jar:
啟動成功后:
總結
- 上一篇: android studio 错误: 找
- 下一篇: Beta Daily Scrum 第七天