亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

GateWay動(dòng)態(tài)路由與負(fù)載均衡詳細(xì)介紹

 更新時(shí)間:2022年11月17日 14:59:11   作者:做一道光  
這篇文章主要介紹了GateWay動(dòng)態(tài)路由與負(fù)載均衡,GateWay支持自動(dòng)從注冊(cè)中心中獲取服務(wù)列表并訪問,即所謂的動(dòng)態(tài)路由

概述

從之前的配置里面我們可以看到我們的 URL 都是寫死的,這不符合我們微服務(wù)的要求,我們微服務(wù)是只要知道服務(wù)的名字,根據(jù)名字去找,而直接寫死就沒有負(fù)載均衡的效果了 默認(rèn)情況下 Gateway 會(huì)根據(jù)注冊(cè)中心的服務(wù)列表,以注冊(cè)中心上微服務(wù)名為路徑創(chuàng)建動(dòng)態(tài)路 由進(jìn)行轉(zhuǎn)發(fā),從而實(shí)現(xiàn)動(dòng)態(tài)路由的功能。

需要注意的是 uri 的協(xié)議為 lb( load Balance ),表示啟用 Gateway 的負(fù)載均衡功能。

lb://serviceName 是 spring cloud gateway 在微服務(wù)中自動(dòng)為我們創(chuàng)建的負(fù)載均衡 uri

協(xié)議:就是雙方約定的一個(gè)接頭暗號(hào)

http : //

項(xiàng)目實(shí)例

1.gateway-server模塊

1.1.pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.it</groupId>
    <artifactId>gateway-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>gateway-server</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

1.2.application.yml文件

server:
  port: 80
spring:
  application:
    name: gateway-server
  cloud:
    gateway:
      enabled: true
      discovery:
        locator:
          enabled: true #開啟動(dòng)態(tài)路由  開啟通過應(yīng)用名稱找到服務(wù)的功能
          lower-case-service-id: true #開啟服務(wù)名稱小寫
eureka:
  client:
    service-url:
      defaultZone: http://192.168.174.133:8761/eureka
    registry-fetch-interval-seconds: 3
  instance:
    hostname: localhost
    instance-id: ${eureka.instance.hostname}:${spring.application.name}:${server.port}

1.3.主函數(shù)類

package com.it;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class GatewayServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayServerApplication.class, args);
    }
}

2.login-service模塊

2.1.pom.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.12.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.it</groupId>
    <artifactId>login-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>login-service</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Hoxton.SR12</spring-cloud.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

2.2.application.yml文件

server:
  port: 8081
spring:
  application:
    name: login-service
eureka:
  client:
    service-url:
      defaultZone: http://192.168.174.133:8761/eureka
    registry-fetch-interval-seconds: 3
  instance:
    hostname: localhost
    instance-id: ${eureka.instance.hostname}:${spring.application.name}:${server.port}

2.3.LoginController文件

package com.it.controller;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.UUID;
public class LoginController {
    @GetMapping("doLogin")
    public String doLogin(String name,String pwd){
        System.out.println(name);
        System.out.println(pwd);
        String s = UUID.randomUUID().toString();
        return s;
    }
}

2.4.主函數(shù)類

package com.it;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class LoginServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(LoginServiceApplication.class, args);
    }
}

3.功能測(cè)試

啟動(dòng)動(dòng)態(tài)路由后,訪問路徑時(shí)需要在localhost后面加上,要訪問服務(wù)的名稱,后面再跟上這個(gè)服務(wù)中的方法接口名

如果不加服務(wù)名稱,還是按照以前的方法寫,會(huì)導(dǎo)致訪問報(bào)404

到此這篇關(guān)于GateWay動(dòng)態(tài)路由與負(fù)載均衡詳細(xì)介紹的文章就介紹到這了,更多相關(guān)GateWay動(dòng)態(tài)路由與負(fù)載均衡內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Java 使用poi把數(shù)據(jù)庫中數(shù)據(jù)導(dǎo)入Excel的解決方法

    Java 使用poi把數(shù)據(jù)庫中數(shù)據(jù)導(dǎo)入Excel的解決方法

    本篇文章介紹了,Java 使用poi把數(shù)據(jù)庫中數(shù)據(jù)導(dǎo)入Excel的解決方法。需要的朋友參考下
    2013-05-05
  • 可視化定時(shí)任務(wù)quartz集成解析全過程

    可視化定時(shí)任務(wù)quartz集成解析全過程

    在開發(fā)中有很多定時(shí)任務(wù)都不是寫死的而是可以人為配置并且寫到數(shù)據(jù)庫中的,下面這篇文章主要給大家介紹了關(guān)于可視化定時(shí)任務(wù)quartz集成解析的相關(guān)資料,需要的朋友可以參考下
    2022-10-10
  • SpringBoot中攔截器和動(dòng)態(tài)代理的區(qū)別詳解

    SpringBoot中攔截器和動(dòng)態(tài)代理的區(qū)別詳解

    在?Spring?Boot?中,攔截器和動(dòng)態(tài)代理都是用來實(shí)現(xiàn)功能增強(qiáng)的,所以在很多時(shí)候,有人會(huì)認(rèn)為攔截器的底層是通過動(dòng)態(tài)代理實(shí)現(xiàn)的,所以本文就來盤點(diǎn)一下他們兩的區(qū)別,以及攔截器的底層實(shí)現(xiàn)吧
    2023-09-09
  • 詳解Spring Cloud Gateway 限流操作

    詳解Spring Cloud Gateway 限流操作

    這篇文章主要介紹了詳解Spring Cloud Gateway 限流操作,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-07-07
  • 如何解決Spring的UnsatisfiedDependencyException異常問題

    如何解決Spring的UnsatisfiedDependencyException異常問題

    這篇文章主要介紹了如何解決Spring的UnsatisfiedDependencyException異常問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • springboot?整合表達(dá)式計(jì)算引擎?Aviator?使用示例詳解

    springboot?整合表達(dá)式計(jì)算引擎?Aviator?使用示例詳解

    本文詳細(xì)介紹了Google?Aviator?這款高性能、輕量級(jí)的?Java?表達(dá)式求值引擎,并通過詳細(xì)的代碼操作演示了相關(guān)API的使用以及如何在springboot項(xiàng)目中進(jìn)行集成,感興趣的朋友一起看看吧
    2024-08-08
  • java操作hdfs的方法示例代碼

    java操作hdfs的方法示例代碼

    這篇文章主要介紹了java操作hdfs的相關(guān)資料,在本地配置Hadoop和Maven的環(huán)境變量,首先需從官網(wǎng)下載與服務(wù)器相同版本的Hadoop安裝包,配置環(huán)境變量后,引入Maven的配置文件,以便管理項(xiàng)目依賴,最后,編寫代碼實(shí)現(xiàn)對(duì)HDFS的連接和操作,完成數(shù)據(jù)的讀寫,需要的朋友可以參考下
    2022-02-02
  • SpringBoot整合RocketMQ實(shí)現(xiàn)發(fā)送同步消息

    SpringBoot整合RocketMQ實(shí)現(xiàn)發(fā)送同步消息

    RocketMQ 是一款開源的分布式消息中間件,由阿里巴巴開源,它具有高可用性、高性能、低延遲等特點(diǎn),廣泛應(yīng)用于阿里巴巴集團(tuán)內(nèi)部以及眾多外部企業(yè)的業(yè)務(wù)系統(tǒng)中,本文給大家介紹了SpringBoot整合RocketMQ實(shí)現(xiàn)發(fā)送同步消息,需要的朋友可以參考下
    2024-04-04
  • Spring AOP訪問目標(biāo)方法的參數(shù)操作示例

    Spring AOP訪問目標(biāo)方法的參數(shù)操作示例

    這篇文章主要介紹了Spring AOP訪問目標(biāo)方法的參數(shù)操作,結(jié)合實(shí)例形式詳細(xì)分析了spring面向切面AOP訪問目標(biāo)方法的參數(shù)相關(guān)實(shí)現(xiàn)步驟與操作注意事項(xiàng),需要的朋友可以參考下
    2020-01-01
  • spring中WebClient如何設(shè)置連接超時(shí)時(shí)間以及讀取超時(shí)時(shí)間

    spring中WebClient如何設(shè)置連接超時(shí)時(shí)間以及讀取超時(shí)時(shí)間

    這篇文章主要給大家介紹了關(guān)于spring中WebClient如何設(shè)置連接超時(shí)時(shí)間以及讀取超時(shí)時(shí)間的相關(guān)資料,WebClient是Spring框架5.0引入的基于響應(yīng)式編程模型的HTTP客戶端,它提供一種簡(jiǎn)便的方式來處理HTTP請(qǐng)求和響應(yīng),需要的朋友可以參考下
    2024-08-08

最新評(píng)論