[ Spring ] Spring Cloud Gateway 2025 Comprehensive Overview

文章目錄

          • Spring Gateway Architecture
          • Project Level Dependency
          • Service Center
          • Service Provider
          • Gateway Service
          • Launch All Service

Spring Gateway Architecture
  • Service Center : register and find service provider
  • Service Provider : programs that provide actual service
  • Gateway Service : dispatch client requests to service providers

data flow : request => gateway => service center => service provider

Project Level Dependency
pluginManagement {repositories {gradlePluginPortal()google()mavenCentral()}
}dependencyResolutionManagement {repositoriesMode = RepositoriesMode.PREFER_SETTINGSrepositories {gradlePluginPortal()google()mavenCentral()}
}buildscript {repositories {gradlePluginPortal()google()mavenCentral()}
}plugins {id("org.jetbrains.kotlin.jvm") version "2.0.21" apply falseid("org.jetbrains.kotlin.kapt") version "2.0.21" apply falseid("org.jetbrains.kotlin.plugin.spring") version "2.0.21" apply falseid("org.springframework.boot") version "3.4.1" apply false
}include("eureka-server")
include("spring-gateway-service")
include("spring-gateway-provider")
Service Center
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:3.4.1")api("org.springframework.boot:spring-boot-starter-web:3.4.1")api("org.springframework.boot:spring-boot-devtools:3.4.1")// eurekaapi("org.springframework.cloud:spring-cloud-starter-netflix-eureka-server:4.2.0")
}
# service
server.port=10001
spring.application.name=eureka-server
# eureka
eureka.instance.hostname=localhost
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
eureka.client.service-url.defaultZone=http://localhost:10001/eureka/
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer@EnableEurekaServer
@SpringBootApplication
class EurekaServerApplicationfun main(args: Array<String>) {runApplication<EurekaServerApplication>(*args)
}
Service Provider
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:3.4.1")api("org.springframework.boot:spring-boot-starter-web:3.4.1")// eurekaapi("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:4.2.0")
}
# service
server.port=10003
spring.application.name=gateway-provider
# eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:10001/eureka/
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication@SpringBootApplication
class GatewayProviderApplicationfun main(args: Array<String>) {runApplication<GatewayProviderApplication>(*args)
}
package x.spring.hello.controllerimport org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController@RestController
class ConfigController {@GetMapping("/config/{key}")fun index(@PathVariable("key") key: String): String {return "config service provider on 10003 key=$key"}
}
Gateway Service
plugins {id("org.jetbrains.kotlin.jvm")id("org.jetbrains.kotlin.kapt")id("org.jetbrains.kotlin.plugin.spring")id("org.springframework.boot")
}java {toolchain {languageVersion = JavaLanguageVersion.of(17)}
}dependencies {val springBootVersion = "3.4.1"val springCloudVersion = "4.2.0"// commonsapi("io.github.hellogoogle2000:kotlin-commons:1.0.19")// kotlinapi("org.jetbrains.kotlin:kotlin-reflect:2.0.21")// springapi("org.springframework.boot:spring-boot-starter:$springBootVersion")api("org.springframework.boot:spring-boot-devtools:$springBootVersion")api("org.springframework.cloud:spring-cloud-starter-bootstrap:$springCloudVersion")// spring cloud gatewayapi("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion")api("org.springframework.cloud:spring-cloud-starter-gateway:$springCloudVersion")api("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:$springCloudVersion")api("javax.servlet:javax.servlet-api:4.0.1")
}
# service
server.port=10002
spring.application.name=gateway-service
# eureka
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.client.service-url.defaultZone=http://localhost:10001/eureka/
# gateway
spring.cloud.gateway.routes[0].id=config
spring.cloud.gateway.routes[0].uri=lb://gateway-provider
spring.cloud.gateway.routes[0].predicates[0]=Path=/config/**
# http://localhost:10002/config/name => http://localhost:10003/config/name
package x.spring.helloimport org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication@SpringBootApplication
class GatewayServiceApplicationfun main(args: Array<String>) {runApplication<GatewayServiceApplication>(*args)
}
package x.spring.hello.componentimport org.springframework.cloud.gateway.route.RouteLocator
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.gateway.route.builder.filters
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration@Configuration
class GatewayRule {@Beanfun rule(builder: RouteLocatorBuilder): RouteLocator {val routes = builder.routes()// http://localhost:10002/github/byteflys => https://github.com/byteflysroutes.route("csdn") { route ->route.filters {rewritePath("/github/(?<variable>.*)", "/\${variable}")}route.path("/github/**").uri("https://github.com/")}return routes.build()}
}
Launch All Service
http://localhost:10001
http://localhost:10003/config/name
http://localhost:10002/config/name => http://localhost:10003/config/name
http://localhost:10002/github/byteflys => https://github.com/byteflys

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/web/67057.shtml
繁體地址,請注明出處:http://hk.pswp.cn/web/67057.shtml
英文地址,請注明出處:http://en.pswp.cn/web/67057.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

GitLab配置免密登錄和常用命令

SSH 免密登錄 Windows免密登錄 刪除現有Key 訪問目錄&#xff1a;C:\Users\Administrator\ .ssh&#xff0c;刪除公鑰&#xff1a;id_rsa.pub &#xff0c;私鑰&#xff1a;id_rsa 2.生成.ssh 秘鑰 運行命令生成.ssh 秘鑰目錄&#xff08; ssh-keygen -t rsa -C xxxxxx126.…

VUE的安裝

要用vue必須要先安裝nodejs nodejs的安裝及環境配置 1.下載安裝包 下載地址&#xff1a; https://nodejs.org/zh-cn/download/ 2.安裝程序 下載完成后&#xff0c;雙擊安裝包開始安裝 ①點擊next ②點同意、next ③默認路徑是C:\Program Files\nodejs\&#xff0c;可修改…

chrome插件:網頁圖片高清下載

前置條件&#xff1a; 安裝有chrome谷歌瀏覽器的電腦 使用步驟&#xff1a; 1.打開chrome擴展插件 2.點擊管理擴展程序 3.加載已解壓的擴展程序 4.選擇對應文件夾 5.成功后會出現一個擴展小程序 6.點擊對應小程序 7.輸入需要訪問的網址&#xff0c;點擊擴展插件即可進行圖片…

[操作系統] 進程地址空間管理

虛擬地址空間的初始化 缺頁中斷 缺頁中斷的概念 缺頁中斷&#xff08;Page Fault Interrupt&#xff09; 是指當程序訪問的虛擬地址在頁表中不存在有效映射&#xff08;即該頁未加載到內存中&#xff09;時&#xff0c;CPU 會發出一個中斷信號&#xff0c;請求操作系統加載所…

HTML5 Web Worker 的使用與實踐

引言 在現代 Web 開發中&#xff0c;用戶體驗是至關重要的。如果頁面在執行復雜計算或處理大量數據時變得卡頓或無響應&#xff0c;用戶很可能會流失。HTML5 引入了 Web Worker&#xff0c;它允許我們在后臺運行 JavaScript 代碼&#xff0c;從而避免阻塞主線程&#xff0c;保…

Nginx配置中的常見錯誤:SSL參數解析

摘要 在高版本的Nginx中&#xff0c;用戶可能會遇到unknown directive “ssl”的錯誤提示。這是因為舊版本中使用的ssl on參數已被棄用。正確的配置SSL加密的方法是在listen指令中添加ssl參數。這一改動簡化了配置流程&#xff0c;提高了安全性。用戶應更新配置文件以適應新版本…

適用于IntelliJ IDEA 2024.1.2部署Tomcat的完整方法,以及筆者踩的坑,避免高血壓,保姆級教程

Tips:創建部署Tomcat直接跳轉到四 一、軟件準備 筆者用的是IntelliJ IDEA 2024.1.2和Tomcat 8.5。之前我使用的是Tomcat 10&#xff0c;但遇到了許多問題。其中一個主要問題是需要使用高于1.8版本的JDK&#xff0c;為此我下載了新的JDK版本&#xff0c;但這又引發了更多的兼容…

微信閱讀網站小程序的設計與實現(LW+源碼+講解)

專注于大學生項目實戰開發,講解,畢業答疑輔導&#xff0c;歡迎高校老師/同行前輩交流合作?。 技術范圍&#xff1a;SpringBoot、Vue、SSM、HLMT、小程序、Jsp、PHP、Nodejs、Python、爬蟲、數據可視化、安卓app、大數據、物聯網、機器學習等設計與開發。 主要內容&#xff1a;…

從零開始學 HTML:構建網頁的基本框架與技巧

系列文章目錄 01-從零開始學 HTML&#xff1a;構建網頁的基本框架與技巧 文章目錄 系列文章目錄前言一、HTML 文檔的基本框架1.1 <!DOCTYPE html>、<html>、<head>、<body> 標簽解析1.1.1 <!DOCTYPE html> 標簽1.1.2 <html> 標簽1.1.3 &l…

C#加密方式

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Security.Cryptography;using System.Text;namespace PwdDemo{public class AESHelper{/// <summary>/// AES 加密/// </summary>/// <param name"str&qu…

【12】WLC配置internal DHCP服務器

1.概述 WLC無線控制器包含內部DHCP(internal DHCP)服務器。該功能通常用于尚未擁有DHCP服務器的分支機構中。 無線網絡通常包含最多10個AP或更少的AP,并且AP在與控制器的同一IP子網上。內部DHCP服務器為無線客戶端、直連AP和從AP中繼的DHCP請求提供了DHCP地址。 2.內部DHC…

vue2中trhee.js加載模型展示天空盒子

![在這里插入圖片描述](https://i-blog.csdnimg.cn/direct/13b9193d6738428791fc1ff112e03627.png 加載模型的時候需要把模型放在public文件下面 創建場景 this.scene new THREE.Scene()創建相機 this.camera new THREE.PerspectiveCamera(45,this.viewNode.clientWidth / t…

汽車免拆診斷案例 | 2007 款日產天籟車起步加速時偶爾抖動

故障現象  一輛2007款日產天籟車&#xff0c;搭載VQ23發動機&#xff08;氣缸編號如圖1所示&#xff0c;點火順序為1-2-3-4-5-6&#xff09;&#xff0c;累計行駛里程約為21萬km。車主反映&#xff0c;該車起步加速時偶爾抖動&#xff0c;且行駛中加速無力。 圖1 VQ23發動機…

對神經網絡基礎的理解

目錄 一、《python神經網絡編程》 二、一些粗淺的認識 1&#xff09; 神經網絡也是一種擬合 2&#xff09;神經網絡不是真的大腦 3&#xff09;網絡構建需要反復迭代 三、數字圖像識別的實現思路 1&#xff09;建立一個神經網絡類 2&#xff09;權重更新的具體實現 3&am…

新項目傳到git步驟

1.首先創建遠程倉庫,創建一個空白項目,即可生成一個克隆URL,可以是http也可以是SSH,copy下這個地址 2.找到項目的本機目錄,進入根目錄,打開git bash here命令行 3.初始化: git init 4.關聯遠程地址: git remote add origin "遠程倉庫的URL" 5.查看關聯 git re…

PAT甲級-1024 Palindromic Number

題目 題目大意 一個非回文數&#xff0c;加上它的翻轉數所得的和&#xff0c;進行k次&#xff0c;有可能會得到一個回文數。給出一個數n&#xff0c;限制相加次數為k次&#xff0c;如果小于k次就得到回文數&#xff0c;那么輸出該回文數和相加的次數&#xff1b;如果進行k次還…

appium自動化環境搭建

一、appium介紹 appium介紹 appium是一個開源工具、支持跨平臺、用于自動化ios、安卓手機和windows桌面平臺上面的原生、移動web和混合應用&#xff0c;支持多種編程語言(python&#xff0c;java&#xff0c;Ruby&#xff0c;Javascript、PHP等) 原生應用和混合應用&#xf…

C#高級:常用的擴展方法大全

1.String public static class StringExtensions {/// <summary>/// 字符串轉List&#xff08;中逗 英逗分隔&#xff09;/// </summary>public static List<string> SplitCommaToList(this string data){if (string.IsNullOrEmpty(data)){return new List&…

【Numpy核心編程攻略:Python數據處理、分析詳解與科學計算】1.1 從零搭建NumPy環境:安裝指南與初體驗

1. 從零搭建NumPy環境&#xff1a;安裝指南與初體驗 NumPy核心能力圖解&#xff08;架構圖&#xff09; NumPy 是 Python 中用于科學計算的核心庫&#xff0c;它提供了高效的多維數組對象以及用于處理這些數組的各種操作。NumPy 的核心能力可以概括為以下幾個方面&#xff1a…

【SpringBoot教程】Spring Boot + MySQL + HikariCP 連接池整合教程

&#x1f64b;大家好&#xff01;我是毛毛張! &#x1f308;個人首頁&#xff1a; 神馬都會億點點的毛毛張 在前面一篇文章中毛毛張介紹了SpringBoot中數據源與數據庫連接池相關概念&#xff0c;今天毛毛張要分享的是關于SpringBoot整合HicariCP連接池相關知識點以及底層源碼…