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-支持
<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-gateway
  cloud:
    sentinel:
      eager: true # 提前触发初始化
      transport:
        port: 8719
        dashboard: 192.168.60.129:8080
    nacos:
      discovery:
        server-addr: 192.168.60.129:8848
    gateway:
      routes:
#        - id: service-provider
#          uri: lb://service-provider
#          predicates:
#            # 匹配所有hello开头的接口 也可以是 context-path 名称
#            - Path=/hello/**
        - id: cloud-sentine-open-feign-provider
          uri: lb://cloud-sentine-open-feign-provider
          predicates:
            - 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)的更多相关文章
- 0.9.0.RELEASE版本的spring cloud alibaba sentinel实例
		sentinel即哨兵,相比hystrix断路器而言,它的功能更丰富.hystrix仅支持熔断,当服务消费方调用提供方发现异常后,进入熔断:sentinel不仅支持异常熔断,也支持响应超时熔断,另外还 ... 
- Spring Cloud Gateway  扩展支持动态限流
		之前分享过 一篇 <Spring Cloud Gateway 原生的接口限流该怎么玩>, 核心是依赖Spring Cloud Gateway 默认提供的限流过滤器来实现 原生Request ... 
- Spring Cloud gateway 五 Sentinel整合
		微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ... 
- Spring Cloud gateway 六 Sentinel nacos存储动态刷新
		微服务当前这么火爆的程度,如果不能学会一种微服务框架技术.怎么能升职加薪,增加简历的筹码?spring cloud 和 Dubbo 需要单独学习.说没有时间?没有精力?要学俩个框架?而Spring C ... 
- Spring Cloud gateway 七 Sentinel  注解方式使用
		Sentinel 注解支持 @SentinelResource 用于定义资源,并提供可选的异常处理和 fallback 配置项. @SentinelResource 注解包含以下属性: value:资 ... 
- 阿里Sentinel支持Spring Cloud Gateway啦
		1. 前言 4月25号,Sentinel 1.6.0 正式发布,带来 Spring Cloud Gateway 支持.控制台登录功能.改进的热点限流和注解 fallback 等多项新特性,该出手时就出 ... 
- 0.9.0.RELEASE版本的spring cloud alibaba sentinel+gateway网关实例
		sentinel除了让服务提供方.消费方用之外,网关也能用它来限流.我们基于上次整的网关(参见0.9.0.RELEASE版本的spring cloud alibaba nacos+gateway网关实 ... 
- springcloud gateway整合sentinel
		1.引入依赖 <parent> <groupId>org.springframework.boot</groupId> <artifactId>spri ... 
- SpringCloud Gateway高阶之Sentinel限流、熔断
		前言 为什么需要服务熔断和降级?微服务是当前业界的一大趋势,原理就是将单一职责的功能模块独立化为子服务,降低服务间的耦合,服务间互相调用.但是这样也会出现一些问题: 上图中大量微服务互相调用,存在大量 ... 
随机推荐
- STP概述简介及生成树算法
			目录: STP概述 STP简介 生成树算法 选择根网桥 选择根端口 选择指定端口 BPDU(桥协议数据单元) STP利用BPDU选择根网桥 STP的收敛 VLAN与STP关系 MSTP多生成树协议华为 ... 
- C语言:伪代码
			伪代码(Pseudocode)是一种算法描述语言.使用伪代码的目的是为了使被描述的算法可以容易地以任何一种编程语言(C, Java, Pascal)实现.因此,伪代码必须结构清晰,代码简单,可读性好, ... 
- xmind8 Mac序列号
			1.首先去官网下载xmind8的安装包:XMind for Mac 也可以去我的百度网盘下载: 链接:https://pan.baidu.com/s/1eY52YsSaPmr-YFhB62Cli ... 
- 雪花算法(SnowFlake)Java实现
			分布式id生成算法的有很多种,Twitter的SnowFlake就是其中经典的一种. 算法原理 SnowFlake算法生成id的结果是一个64bit大小的整数,它的结构如下图: 1bit,不用,因为二 ... 
- [考试总结]noip模拟10
			不小心有咕掉了一段时间 这次考试咕掉的分数也是太多了 然后就是这次暴力完全没有打满 遗憾啊遗憾 T1 入阵曲 前面的题目背景故意引导我们去往矩阵快速幂的方向去想 然而半毛钱关系没有 其实就是维护前缀和 ... 
- Echarts的应用实践
			Echarts官网:https://echarts.apache.org/ echarts是百度推出的,使用JavaScript实现的开源可视化库,可以提供直观.可定制化的数据可视化图表,包括折线图. ... 
- javascript学习--(四)面向对象:
			一.生成器generator: javascript里的generator函数是用function*定义的, 案例:yield 也会返回 function* foo(x){ yield x+1; yi ... 
- Xmanager7 xshell7 xftp7安装破解教程
			NetSarang Xmanager7 Power Suite是可以浏览远端X窗口系统的软件,远程把Unix/Linux的桌面无缝地带到Windows桌面上.旗下的Xshell Xftp插件是一款常用 ... 
- g6踩坑
			1. 当父元素有transform: scale()时,有鼠标定位不准确的问题 // 开启支持css缩放,智能保证基本的准确,很多情况还是有问题 graph.get('canvas').set('su ... 
- chanakya
			仅供个人娱乐 参考http://www.saulgoodman.cn/HA-Chanakya.html 靶机信息 https://www.vulnhub.com/entry/ha-chanakya,3 ... 
