欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SpringCloud_Eureka服務注冊與發(fā)現基礎及構建步驟

 更新時間:2023年01月31日 11:06:39   作者:Knight_AL  
Eureka服務注冊中心,主要用于提供服務注冊功能,當微服務啟動時,會將自己的服務注冊到Eureka Server,這篇文章主要介紹了SpringCloud中Eureka的配置及詳細使用,需要的朋友可以參考下

代碼鏈接

https://github.com/lidonglin-bit/cloud

一、Eureka基礎知識

1.什么是服務治理

SpringCloud封裝了Netflix公司開發(fā)的Eureka模塊來實現服務治理。

在傳統的RPC遠程調用框架中,管理每個服務與服務之間依賴關系比較復雜、所以需要進行服務治理,管理服務與服務之間依賴關聯,以實現服務調用,負載均衡、容錯等,實現服務發(fā)現與注冊。

2.什么是服務注冊

Eureka采用了CS的設計架構,Eureka Server作為服務注冊功能的服務器,它是服務注冊中心。

而系統中的其他微服務,使用Eureka的客戶端連接到Eureka Server并維持心跳連接。這樣系統的維護人員可以通過Eureka Server來監(jiān)控系統中各個微服務是否正常運行。

在服務注冊與發(fā)現中,有一個注冊中心。當服務器啟動的時候,會把當前自己服務器的信息,比如:服務通訊地址等以別名方式注冊到注冊中心上。

另一方(消費者服務),以該別名的方式去注冊中心上獲取到實際的服務通訊地址,然后,再實現本地RPC遠程調用。

RPC遠程調用框架核心設計思想:在于注冊中心,因為使用注冊中心管理每個服務與服務之間的一個依賴關系(服務治理概念)。

在任何RPC遠程框架中,都會有一個注冊中心(存放服務地址相關信息(接口地址))。

3.Eureka兩組件

Eureka Server提供服務注冊服務

各個微服務節(jié)點通過配置啟動后,會在Eureka Server中進行注冊,這樣Eureka Server中的服務注冊表中將會存儲所有可用服務節(jié)點的信息,服務節(jié)點的信息可以在界面中直觀看到。

Eureka Client通過注冊中心進行訪問

是一個Java客戶端,用于簡化Eureka Server的交互,客戶端同時也具備一個內置的、使用輪詢(round-robin)負載算法的負載均衡器。在應用啟動后,將會在Eureka Server發(fā)送心跳(默認周期30秒)。如果Eureka Server在多個心跳周期內沒有收到某個節(jié)點的心跳,Eureka Server將會從服務注冊表中把這個服務節(jié)點移出(默認90秒)

二、單機Eureka構建步驟

整體結構

父工程pom文件

  <!-- 統一管理jar包版本 -->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <!-- 子模塊繼承之后,提供作用:鎖定版本+子modlue不用寫groupId和version  -->
    <dependencyManagement>
        <dependencies>
            <!--spring boot 2.2.2-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud Hoxton.SR1-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud alibaba 2.1.0.RELEASE-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.1.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

1.IDEA生成eurekaServer端服務注冊中心

1.建Module:cloud-eureka-server7001

2.改POM

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>
</project>

1.X和2.X的對比說明

1.X版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
2.X版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>

3.寫YML

server:
  port: 7001
spring:
  application:
    name: cloud-eureka-server7001
eureka:
  instance:
    hostname: localhost
  #因為服務端不需要注冊,所有為false
  client:
    register-with-eureka: false
    fetchRegistry: false
    service-url:
      defaultZone: http://localhost:7001/eureka

4.主啟動

@SpringBootApplication
@EnableEurekaServer
public class EurekaMain7001 {
    public static void main(String[] args) {
        SpringApplication.run(EurekaMain7001.class,args);
    }
}

5.測試

http://localhost:7001/

2.服務提供者

EurekaClient端cloud-provider-payment8001將注冊進EurekaServer成為服務提供者provider

1.建Module:cloud-provider-payment8001

2.改POM

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

3.寫YML

spring:
  application:
    name: cloud-provider-payment8001
server:
  port: 8001
eureka:
  client:
    register-with-eureka: true
    fetchRegistry: true
    service-url:
      defaultZone: http://localhost:7001/eureka

4.主啟動

@SpringBootApplication
@EnableEurekaClient
public class PaymentMain8001 {
    public static void main(String[] args) {
        SpringApplication.run(PaymentMain8001.class,args);
    }
}

5.測試

先啟動EurekaServer

http://localhost:7001/

3.服務消費者

EurekaClient端cloud-consumer-order80將注冊進EurekaServer成為服務消費者consumer

1.建Module:cloud-consumer-order80

2.改POM

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

3.寫YML

spring:
  application:
    name: cloud-consumer-order80
server:
  port: 80
eureka:
  client:
    register-with-eureka: true
    fetchRegistry: true
    service-url:
      defaultZone: http://localhost:7001/eureka

4.主啟動

@SpringBootApplication
@EnableEurekaClient
public class OrderMain80 {
    public static void main(String[] args) {
        SpringApplication.run(OrderMain80.class,args);
    }
}

5.測試

1)先要啟動EurekaServer,7001服務

2)再要啟動服務提供者8001服務和服務消費者80服務

3)eureka服務器

4)測試查詢:http://localhost/consumer/payment/get/31

5)測試添加:postman測試添加

6)測試8001服務和80服務效果一樣

到此這篇關于SpringCloud_Eureka服務注冊與發(fā)現基礎及構建步驟的文章就介紹到這了,更多相關SpringCloud_Eureka內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

  • Java動態(tài)代理靜態(tài)代理實例分析

    Java動態(tài)代理靜態(tài)代理實例分析

    這篇文章主要介紹了Java動態(tài)代理靜態(tài)代理實例分析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-03-03
  • 解析maven的用法和幾個常用的命令(推薦)

    解析maven的用法和幾個常用的命令(推薦)

    maven最大的作用就是用于對項目中jar包依賴的統一管理。這篇文章主要介紹了maven的用法和幾個常用的命令,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • spring中通過ApplicationContext getBean獲取注入對象的方法實例

    spring中通過ApplicationContext getBean獲取注入對象的方法實例

    今天小編就為大家分享一篇關于spring中通過ApplicationContext getBean獲取注入對象的方法實例,小編覺得內容挺不錯的,現在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2019-03-03
  • Javaweb使用Maven工具與Tomcat的方法詳解

    Javaweb使用Maven工具與Tomcat的方法詳解

    這篇文章主要為大家詳細介紹了Javaweb使用Maven工具與Tomcat的方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • 使用restTemplate.postForEntity()的問題

    使用restTemplate.postForEntity()的問題

    這篇文章主要介紹了使用restTemplate.postForEntity()的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-09-09
  • Java信號量Semaphore原理及代碼實例

    Java信號量Semaphore原理及代碼實例

    這篇文章主要介紹了Java信號量Semaphore原理及代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-10-10
  • Java RateLimiter的限流詳解

    Java RateLimiter的限流詳解

    這篇文章主要為大家詳細介紹了Java RateLimiter的限流,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • Spring集成Seata方式(案例演示)

    Spring集成Seata方式(案例演示)

    這篇文章主要介紹了Spring集成Seata方式,本案例使用Seata-All演示,結合實例代碼給大家講解的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-08-08
  • Java IO流之原理分類與節(jié)點流文件操作詳解

    Java IO流之原理分類與節(jié)點流文件操作詳解

    流(Stream)是指一連串的數據(字符或字節(jié)),是以先進先出的方式發(fā)送信息的通道,數據源發(fā)送的數據經過這個通道到達目的地,按流向區(qū)分為輸入流和輸出流
    2021-10-10
  • java導出json格式文件的示例代碼

    java導出json格式文件的示例代碼

    本篇文章主要介紹了java導出json格式文件的示例代碼,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-09-09

最新評論