栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringCloudAlibaba-Gateway集成Sentinel

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringCloudAlibaba-Gateway集成Sentinel

一、概述

首先要复习一下Gateway

SpringCloud-服务网关-Gateway

服务网关在微服务架构中充当了请求访问入口的角色,是非常重要的一个部分,在高并发的系统中我们通常会在网关层通过流控降级等手段把多余的请求拒绝在外来防止微服务被高并发请求打垮。

二、实例 一.依赖

alibaba专门为gateway提供了一个适配包“spring-cloud-alibaba-sentinel-gateway”

  
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
        
        
        
            com.alibaba.csp
            sentinel-datasource-nacos
        
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-sentinel
        

        
        
            com.alibaba.cloud
            spring-cloud-alibaba-sentinel-gateway
        
        
            org.springframework.cloud
            spring-cloud-starter-gateway
        
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-config
        
二.配置文件
server:
  port: 8408

spring:
  application:
    name: cloudalibaba-sentinel-gateway
  cloud:
    nacos:
      discovery:
        server-addr: 119.91.99.85:8849
    sentinel:
      transport:
        dashboard: localhost:8080 #配置Sentinel dashboard地址
        port: 8719 #应用与Sentinel控制台交互的端口
      datasource:
        ds1:
          nacos: #nacos限流持久配置
            server-addr: 119.91.99.85:8849 #nacos地址
            dataId: ${spring.application.name}  #获取限流的数据源的dataId
            groupId: DEFAULT_GROUP #获取限流的数据源的分组
            data-type: json #数据类型
            rule-type: flow #规则类型
      eager: true #取消懒加载
    gateway:
      discovery:
        locator:
          lower-case-service-id: true # 表明gateway开启服务注册和发现的功能
      routes: #添加路由规则
        - id: nacos-payment-provider #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名
          uri: lb://nacos-payment-provider #匹配后提供服务的路由地址
          predicates:
            - Path=/payment/nacos/**         # 断言,路径相匹配的进行路由

management:
  endpoints:
    web:
      exposure:
        include: '*'
三.Nacos配置gateway流控规则
在这里插入代码片
四.
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/310208.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号