说明: 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作网关限流的更多相关文章

  1. Spring Cloud Alibaba 使用Sentinel实现接口限流

    Sentinel是什么 Sentinel的官方标题是:分布式系统的流量防卫兵.从名字上来看,很容易就能猜到它是用来作服务稳定性保障的.对于服务稳定性保障组件,如果熟悉Spring Cloud的用户,第 ...

  2. spring cloud gateway(三、实现限流)

    限流一般有两个实现方式,令牌桶和漏桶 金牌桶是初始化令牌(容器)的个数,通过拿走里边的令牌就能通过, 没有令牌不能报错,可以设置向容器中增加令牌的速度和最大个数 漏桶是向里边放入请求,当请求数量达到最 ...

  3. Spring Cloud Gateway 整合阿里 Sentinel网关限流实战!

    大家好,我是不才陈某~ 这是<Spring Cloud 进阶>第八篇文章,往期文章如下: 五十五张图告诉你微服务的灵魂摆渡者Nacos究竟有多强? openFeign夺命连环9问,这谁受得 ...

  4. Spring Cloud gateway 五 Sentinel整合

    微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ...

  5. Spring Cloud gateway 六 Sentinel nacos存储动态刷新

    微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ...

  6. Spring Cloud Gateway + Jwt + Oauth2 实现网关的鉴权操作

    Spring Cloud Gateway + Jwt + Oauth2 实现网关的鉴权操作 一.背景 二.需求 三.前置条件 四.项目结构 五.网关层代码的编写 1.引入jar包 2.自定义授权管理器 ...

  7. Spring Cloud Alibaba整合Sentinel

    Spring Cloud Alibaba 整合 Sentinel 一.需求 二.实现步骤 1.下载 sentinel dashboard 2.服务提供者和消费者引入sentinel依赖 3.配置控制台 ...

  8. 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 ...

  9. Spring Cloud Gateway(二):Spring Cloud Gateway整合Eureka应用

    Spring Cloud Gateway 应用概述 下面的示例启动两个服务:gataway-server 和 user-service 都注册到注册中心 Eureka上,客户端请求后端服务[user- ...

随机推荐

  1. linux之磁盘整理

    yum安装的时候报错没有磁盘空间,需要整理 就需要查看下目前的磁盘使用情况 首先是df -hl查看从磁盘使用 可以到根目录下看看文件夹大小 du -sh * 或者下面的命令 接下来我们要删除东西整理磁 ...

  2. 给你的MyBatis-Plus装上批量插入的翅膀

    努力和选择,哪个更重要?关注微信公众号[天开易想]这是一位懂互联网研发和架构的户外.篮球老铁 前言 各位好,我是易哥(thinkYi). 大家有用过MyBatis-Plus(简称MP)的都知道它是一个 ...

  3. Ubuntu中卸载node和npm并重装

    1.node 和 npm 卸载不干净 #apt-get 卸载 sudo apt-get remove --purge npm sudo apt-get remove --purge nodejs su ...

  4. Android Handler 分析学习

    一.Handler简介 Handler 是 Android 中用于线程间交互的机制.与其相关的概念有 Thread.Looper.Runnable.Message.MessageQueue 等. Go ...

  5. django 的跨域配置

    1.跨域原理 #1. 首先浏览器安全策略限制js ajax跨域访问服务器 #2. 如果服务器返回的头部信息中有当前域: // 允许 http://localhost:8080 这个网站打开的页面中的j ...

  6. (转载)IO模型

    本文转载自网络. 如有侵权,请联系处理! 简介 参考<UNIX Network Programming Volume 1, ThirdEdition [Electronic resources] ...

  7. (转载)什么是B树?

    本文转载自网络. 如有侵权,请联系处理!  

  8. Centos-搜索文件或目录-find

    find 在指定的目录下查找指定的文件 相关选项 -type 指定文件类型 -name   指定文件名字,支持通配符 -gid   指定用户组ID -uid   指定用户ID -empty 查找长度为 ...

  9. matlab中fix, floor, ceil, round 函数的使用方法

    转载: https://www.ilovematlab.cn/thread-91895-1-1.html Matlab取整函数有: fix, floor, ceil, round.具体应用方法如下: ...

  10. 使用EasyX和C++写一个消砖块游戏

    第一次玩EasyX,写一个比较简单的消砖块游戏. 主函数包括Game的类的开始,运行和结束. 1 #include "BrickElimination.h" 2 3 int mai ...