sentinel使用(结合gateway)
前
如果你想在Spring Cloud Gateway中使用Sentinel Starter,你需要添加Spring - Cloud -alibaba- Sentinel - Gateway依赖,并添加Spring - Cloud - Starter - Gateway依赖,让Spring Cloud Gateway自动配置类在模块中生效
帮助文档: https://github.com/alibaba/spring-cloud-alibaba/wiki/Sentinel#spring-cloud-gateway-%E6%94%AF%E6%8C%81
<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>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>
搭建环境
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.2.5.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.wzq.example</groupId><artifactId>cloud_sentine_gateway</artifactId><version>0.0.1-SNAPSHOT</version><name>cloud_sentine_gateway</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version><spring.cloud.version>Hoxton.SR8</spring.cloud.version><spring.cloud.alibaba.version>2.2.5.RELEASE</spring.cloud.alibaba.version><spring.boot.version>2.2.5.RELEASE</spring.boot.version></properties><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><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>${spring.cloud.alibaba.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</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>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-gateway</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>
注意:spring的版本需要一致
重点jar: spring-cloud-starter-alibaba-nacos-discovery , spring-cloud-alibaba-sentinel-gateway , spring-cloud-starter-gateway
application.yml
server:port: 8085
spring:application:name: cloud-sentine-gatewaycloud:sentinel:eager: true # 提前触发初始化transport:port: 8719dashboard: 192.168.60.129:8080nacos:discovery:server-addr: 192.168.60.129:8848gateway:routes:
# - id: service-provider
# uri: lb://service-provider
# predicates:
# # 匹配所有hello开头的接口 也可以是 context-path 名称
# - Path=/hello/**- id: cloud-sentine-open-feign-provideruri: lb://cloud-sentine-open-feign-providerpredicates:- Path=/hello/**
management:endpoints:web:exposure:include: "*"
CloudSentineGatewayApplication.java
package com.wzq.example.cloud_sentine_gateway;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@EnableDiscoveryClient
@SpringBootApplication
public class CloudSentineGatewayApplication {public static void main(String[] args) {SpringApplication.run(CloudSentineGatewayApplication.class, args);}}
测试
在控制台中添加 cloud-sentine-gateway 的限流规则
访问接口要是出现:限流成功
{"code": 429,"message": "Blocked by Sentinel: FlowException"
}
sentinel使用(结合gateway)相关推荐
- gateway sentinel 熔断 不起作用_Spring Cloud Alibaba集训营第五天(服务熔断和限流)
前言:为什么需要流控降级 我们的生产环境经常会出现一些不稳定的情况,如: 大促时瞬间洪峰流量导致系统超出最大负载,load 飙高,系统崩溃导致用户无法下单 "黑马"热点商品击穿缓存 ...
- SpringCloud 2020版本教程3:使用sentinel作为熔断器
点击关注公众号,Java干货及时送达 什么是sentinel Sentinel,中文翻译为哨兵,是为微服务提供流量控制.熔断降级的功能,它和Hystrix提供的功能一样,可以有效的解决微服务调用产生的 ...
- spring gateway 限流持久化_Spring Cloud Gateway 扩展支持动态限流
之前分享过 一篇 <Spring Cloud Gateway 原生的接口限流该怎么玩>, 核心是依赖Spring Cloud Gateway 默认提供的限流过滤器来实现 原生Request ...
- 限流神器Sentinel与nacos数据双向同步
sentinel与springcloud.spring cload alibaba 版本选择 版本参考: 版本说明 · alibaba/spring-cloud-alibaba Wiki · GitH ...
- 四阶段--day06-网关Gateway 应用实践
目录 一 网关 1 背景介绍 2 网关定义 2.1 Spring Cloud Gateway优缺点分析 3 网关的入门步骤 3.1 业务需求 3.2 01-sca父工程下创建sca-gateway子模 ...
- Nacos,Sentine限流熔断,Gateway网关
文章目录 建立项目 注册中心简介 背景分析 Nacos概述 构建Nacos服务 准备工作 If use MySQL as datasource: Count of DB: Connect URL of ...
- 【Sentinel】
提示:写完文章后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 一. 服务雪崩 二. 断路器 三. Sentinel的下载和安装 Windows下安装 docker安装 四.初始化监控 1 ...
- 那些年,我的数据结构课设,现在满满的回忆!(现如今身处内卷之中,已经很难出现当初那份乐趣了)
一.看到这个图标很有感觉 距离当初完成数据结构课设已经过去很久很久了,当初由于U盘失踪,也丢失了很多宝贵的东西,我也伤心的好久`(>﹏<)′!不过最近找到了失散多年的亲兄弟,打开U盘,感概 ...
- (企业案例)使用Nacos持久化规则,改造sentinel-dashboard
文章目录 一.前言 1. 版本选取 2. 克隆代码 3. 导入 IDEA 二.全局修改 2.1. 修改 POM 2.2. 修改配置文件 三.后端代码修改 3.1. 包结构部分 3.2. nacos 配 ...
最新文章
- 入机器学习大坑,需要什么样的数学水平?
- R语言使用ggplot2包使用geom_violin函数绘制小提琴图(水平小提琴图、垂直小提琴图、边缘不截断小提琴图)实战
- python中文叫什么意思-在python中%是什么意思
- 严蔚敏数据结构:链表实现一元多项式相加
- php二进制加密_怎样给PHP源代码加密?PHP二进制加密与解密的解决办法
- IAR 窗口重置默认配置
- 右击计算机没有管理员权限,电脑怎么获得管理员权限(管理员权限怎么设置)...
- 神经网络模型如何使用的,神经网络模型是干嘛的
- kali攻击139端口_简易入侵139端口
- Dos系统功能的调用
- 在线CHM阅读器(2)——文件提取及关键文件解析
- nm命令和其内容详解
- 《PyQT5软件开发 - 控件篇》第3章 单行文本框QLineEdit
- IE浏览器一打开就提示“已停止工作”的解决方案
- 容器CICD实践:基于Helm实现应用交付自动回滚
- 语言模型(五)—— Seq2Seq、Attention、Transformer学习笔记
- sql server中如何修改视图中的数据?
- 二叉树的中序遍历-递归和非递归算法
- 三、JumpServer堡垒机用户使用手册
- C Primer Plus (第六版)编程练习参考答案
热门文章
- 后序遍历的非递归算法python_二叉树后序遍历(递归与非递归)算法C语言实现...
- mysql 事务_MySQL事务
- SBIO | 许金荣/江聪团队报道禾谷镰刀菌MAPKs介导的生长发育、逆境响应及生物互作机制...
- SEL重磅:重新认识菌根:菌根真的如普遍认为的那样重要吗?
- Nature子刊:微生物系统的功能与功能冗余
- R语言绘图:28个实用程序包
- seaborn使用violinplot函数可视化水平小提琴图(Make Horizontal Violin Plot with violinplot in Seaborn)
- pandas使用replace函数移除dataframe数值数据中的逗号并基于处理后的数据生成新的整型数据列(remove comma from column values in Pandas)
- R语言ggplot2可视化散点图实战:绘制基础散点图、为所有散点添加标签、只为大于阈值的散点添加标签
- R语言Welch方差分析(Welch’s ANOVA)实战:Welch方差分析是典型的单因素方差分析的一种替代方法,当方差相等的假设被违反时我们无法使用单因素方差分析,这时候Welch’s出来救场了