spring cloud gateway整合sentinel作网关限流
说明: sentinel可以作为各微服务的限流,也可以作为gateway网关的限流组件。 spring cloud gateway有限流功能,但此处用sentinel来作为替待。
说明:sentinel流控可以放在gateway网关端,也可以放在各微服务端。
1,以父工程为基础,创建子工程
2,添加pom依赖
<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,添加配置项
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限流后的响应配置
3,启动类
@SpringBootApplication
@EnableDiscoveryClient
public class GatewaySentinelApplication {
public static void main(String[] args) { SpringApplication.run(GatewaySentinelApplication.class, args);
}
}
4,启动后,在sentinel控制台可以看到 gateway-sentinel 应用,可以通过控制台设置流控规则。
spring cloud gateway整合sentinel作网关限流的更多相关文章
- Spring Cloud Alibaba 使用Sentinel实现接口限流
Sentinel是什么 Sentinel的官方标题是:分布式系统的流量防卫兵.从名字上来看,很容易就能猜到它是用来作服务稳定性保障的.对于服务稳定性保障组件,如果熟悉Spring Cloud的用户,第 ...
- spring cloud gateway(三、实现限流)
限流一般有两个实现方式,令牌桶和漏桶 金牌桶是初始化令牌(容器)的个数,通过拿走里边的令牌就能通过, 没有令牌不能报错,可以设置向容器中增加令牌的速度和最大个数 漏桶是向里边放入请求,当请求数量达到最 ...
- Spring Cloud Gateway 整合阿里 Sentinel网关限流实战!
大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第八篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...
- Spring Cloud gateway 五 Sentinel整合
微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ...
- Spring Cloud gateway 六 Sentinel nacos存储动态刷新
微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ...
- Spring Cloud Gateway + Jwt + Oauth2 实现网关的鉴权操作
Spring Cloud Gateway + Jwt + Oauth2 实现网关的鉴权操作 一.背景 二.需求 三.前置条件 四.项目结构 五.网关层代码的编写 1.引入jar包 2.自定义授权管理器 ...
- Spring Cloud Alibaba整合Sentinel
Spring Cloud Alibaba 整合 Sentinel 一.需求 二.实现步骤 1.下载 sentinel dashboard 2.服务提供者和消费者引入sentinel依赖 3.配置控制台 ...
- API网关性能比较:NGINX vs. ZUUL vs. Spring Cloud Gateway vs. Linkerd API 网关出现的原因
API网关性能比较:NGINX vs. ZUUL vs. Spring Cloud Gateway vs. Linkerd http://www.infoq.com/cn/articles/compa ...
- Spring Cloud Gateway(二):Spring Cloud Gateway整合Eureka应用
Spring Cloud Gateway 应用概述 下面的示例启动两个服务:gataway-server 和 user-service 都注册到注册中心 Eureka上,客户端请求后端服务[user- ...
随机推荐
- hystrix(6) 命令执行
上一节中讲到了HystrixCommand有四种执行方法,这一节就来讲一下这四种方法直接的关系以及他们的实现. execute方法使用同步方式获取结果,本质是调用了queue方法获取了一个Future ...
- 从Class源码看反射
日常敲码中,如果想要在程序运行阶段访问某个类的所有信息,并支持修改类的状态或者行为的话,肯定会用到反射,而反射靠的就是Class类.Java的动态代理也用到了这个东西,所以了解其基本操作在苦逼的CRU ...
- windows服务器添加磁盘后,提示The disk is offline because of policy set by an administrator的解决办法
操作系统:Windows Server 2008 R2 Enterprise 事件:存储在虚拟机上添加三块磁盘,笔者准备扩展到E盘(动态分区) 问题:存储团队添加磁盘后,OS的磁盘管理界面,看到提示, ...
- 动态代理:jdk动态代理和cglib动态代理
/** * 动态代理类:先参考代理模式随笔,了解代理模式的概念,分为jdk动态代理和cglib,jdk动态代理是通过实现接口的方式创建代理类的,cglib是通过继承类的方式实现的代理类的 * jdk动 ...
- throw throws try catch finally return
throw throw 语句用于抛出异常,例如 throw new EOFException(). throws 当使用throw 语句抛出checked 异常后,可以不用捕获异常并处理,而是使用 ...
- pytorch和tensorflow的爱恨情仇之基本数据类型
自己一直以来都是使用的pytorch,最近打算好好的看下tensorflow,新开一个系列:pytorch和tensorflow的爱恨情仇(相爱相杀...) 无论学习什么框架或者是什么编程语言,最基础 ...
- Win10系统下的MySQL5.7.24版本(解压版)详细安装教程
进入MySQL官网下载压缩包 MySQL官网:https://www.mysql.com/ 将页面拉到最底,点击MySQL Community Server 跳转到下载页面,默认选择是最新版MySQL ...
- 【题解】[USACO12MAR]Cows in a Skyscraper G
题目链接 题目大意:给定一个集合\(S\),给一个限制条件\(P\),要求划分集合,使得每一个子集\(A\in S\),\(A\)满足限制条件\(P\),且划分总数最小. 注意到数据范围\(n< ...
- 一个Java对象的内存布局
1.对象的创建过程 class loading class linking(verification,preparation,resolution) class initializing 申请对象内存 ...
- Nginx 配置 http 强制跳转到 https
个人真实配置 架构:Nginx 反向代理 + Nginx 前端(LNMP) 在 Nginx 反向代理的 虚拟机主机配置文件中,作如下配置: upstream ilexa_cn { server 192 ...