日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

dubbo教程一

發布時間:2023/12/10 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中;

    然后編寫接口和實現類:

    package com.fan.dubbo.service;public interface DemoService {String hello(String msg); }

    然后是實現類:

    package com.fan.dubbo.service.impl;import com.fan.dubbo.service.DemoService;public class DemoServiceImpl implements DemoService {public String hello(String msg) {return "hello dubbo"+ msg;} }

    將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:



    啟動成功后:

    總結

    以上是生活随笔為你收集整理的dubbo教程一的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。