说明: 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. python实现多分类评价指标

    1.什么是多分类? 参考:https://www.jianshu.com/p/9332fcfbd197 针对多类问题的分类中,具体讲有两种,即multiclass classification和mul ...

  2. 1.Concurrent概述

  3. svn提交代码出错

    今天提交代码的时候一直报错,下面是错误信息 Error: Commit failed (details follow):  Error: Commit blocked by pre-commit ho ...

  4. Spring Boot 自动配置的原理、核心注解以及利用自动配置实现了自定义 Starter 组件

    本章内容 自定义属性快速入门 外化配置 自动配置 自定义创建 Starter 组件 摘录:读书是读完这些文字还要好好用心去想想,写书也一样,做任何事也一样 图 2 第二章目录结构图 第 2 章 Spr ...

  5. 靠这些秋招秘笈,齐姐的学妹今年已经拿到了 8 个offer!

    小齐说: 现在秋招进行时,正在找工作的小伙伴进度都怎么样了呀? 今天这篇文章是我武大的学妹今年秋招的经验分享,庆妹去年才决定转行,现在已手握 N+ 个 offer - 这篇文章干货满满,庆妹对每一块面 ...

  6. spark-1-架构设计&基本流程

    Spark运行架构包括: (1)集群资源管理器(Cluster Manager) (2)运行作业任务的工作节点(Worker Node) (3)每个应用的任务控制节点(Driver)和每个工作节点上负 ...

  7. 阿里云oss对象存储配置CDN

    阿里云oss对象存储配置CDN 1.打开阿里云CDN 2.填写信息,这个地方要注意,我的备案域名是www.ljwXXX.work,我们可以自定义一个域名,test.ljwXXX.work作为加速域名. ...

  8. interp1一维数据插值在matlab中的用法

    转载:https://ww2.mathworks.cn/help/matlab/ref/interp1.html?s_tid=srchtitle#btwp6lt-2_1 interp1 一维数据插值( ...

  9. Batch批处理 间断向EXE发送参数

    参考:https://blog.csdn.net/wjz1029/article/details/45044033 找了很久的一种方法: 怎样向一个EXE 发送一个参数,得到反馈后,再向EXE发送一个 ...

  10. 【题解】【POI2000】病毒

    题目链接 这题让我们构造一个无限长的,不包括给定字符串的01串. 把给定字符串放到\(AC\)自动机上,在结尾处打上标记. 发现,如果我们要构造一个无限长的串,必然要有一个环. 那么这个环上就一定不能 ...