spring cloud gateway整合sentinel實(shí)現(xiàn)網(wǎng)關(guān)限流
這篇文章主要介紹了spring cloud gateway整合sentinel實(shí)現(xiàn)網(wǎng)關(guān)限流,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
說(shuō)明: sentinel可以作為各微服務(wù)的限流,也可以作為gateway網(wǎng)關(guān)的限流組件。 spring cloud gateway有限流功能,但此處用sentinel來(lái)作為替待。
說(shuō)明:sentinel流控可以放在gateway網(wǎng)關(guān)端,也可以放在各微服務(wù)端。
1,以父工程為基礎(chǔ),創(chuàng)建子工程
2,添加pom依賴(lài)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-sentinel-gateway</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
2,添加配置項(xiàng)
server:
port: 9092
spring:
cloud:
nacos:
discovery:
register-enabled: false
server-addr: localhost:8848
namespace: c22e5019-0bee-43b1-b80b-fc0b9d847501
sentinel:
transport:
dashboard: localhost:8080
port: 8719
scg:
fallback:
mode: response
response-status: 455
response-body: error!
gateway:
routes:
- id: demo_route
uri: lb://demo
predicates:
- Path=/demo/**
- id: demo2_test
uri: lb://demo2
predicates:
- Path=/user/**
application:
name: gateway-sentinel
scg.fallback為sentinel限流后的響應(yīng)配置
3,啟動(dòng)類(lèi)
@SpringBootApplication
@EnableDiscoveryClient
public class GatewaySentinelApplication {
public static void main(String[] args) {
SpringApplication.run(GatewaySentinelApplication.class, args);
}
}
4,啟動(dòng)后,在sentinel控制臺(tái)可以看到 gateway-sentinel 應(yīng)用,可以通過(guò)控制臺(tái)設(shè)置流控規(guī)則。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Java基礎(chǔ)總結(jié)之Thymeleaf詳解
Thymeleaf是一種現(xiàn)代的基于服務(wù)器端的Java模板引擎技術(shù),也是一個(gè)優(yōu)秀的面向Java的XML、XHTML、HTML5頁(yè)面模板,它具有豐富的標(biāo)簽語(yǔ)言、函數(shù)和表達(dá)式,在使用Spring Boot框架進(jìn)行頁(yè)面設(shè)計(jì)時(shí),一般會(huì)選擇Thymeleaf模板,需要的朋友可以參考下2021-05-05
Java高并發(fā)BlockingQueue重要的實(shí)現(xiàn)類(lèi)詳解
這篇文章主要給大家介紹了關(guān)于Java高并發(fā)BlockingQueue重要的實(shí)現(xiàn)類(lèi)的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-01-01
詳解Spring與Mybatis的整合方法(基于Eclipse的搭建)
這篇文章主要介紹了Spring與Mybatis的整合方法(基于Eclipse的搭建),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-10-10
Java操作XML轉(zhuǎn)JSON數(shù)據(jù)格式詳細(xì)代碼實(shí)例
在Java中我們可以使用一些現(xiàn)成的庫(kù)來(lái)實(shí)現(xiàn)XML到JSON的轉(zhuǎn)換,下面這篇文章主要給大家介紹了關(guān)于Java操作XML轉(zhuǎn)JSON數(shù)據(jù)格式的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-04-04

