【Spring Cloud、Gateway、Sentinel】搭建Spirng Cloud项目(五):Spring Cloud的Gateway服务整合Sentinel

一、环境准备:同上述其他文章

二、Spring Cloud的Gateway服务整合Sentinel

1、pom依赖

		<!--sentinel断路器依赖-->
        <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-sentinel</artifactId>
        </dependency>

2、bootstrap.yml配置

spring:
  cloud:
    sentinel:
      transport:
        port: 7201
        dashboard: pfhe.com:7003

3、效果展示
在这里插入图片描述

三、Spring Cloud的Gateway服务整合Sentinel,并获取Nacos中的配置。

1、pom依赖

		<dependency>
            <groupId>com.alibaba.csp</groupId>
            <artifactId>sentinel-datasource-nacos</artifactId>
        </dependency>

2、bootstrap.yml配置

spring:
  cloud:
    sentinel:
      transport:
        port: 7201
        dashboard: pfhe.com:7003
      datasource:
        ds-flow:
          nacos:
            server-addr: pfhe.com:7001
            dataId: ${spring.application.name}-sentinel-gateway-flow-rules
            groupId: SENTINEL_GROUP
            namespace: ${spring.profiles.active}
            data-type: json
            rule-type: flow
            username: nacos
            password: nacos
        ds-api:
          nacos:
            server-addr: pfhe.com:7001
            dataId: ${spring.application.name}-sentinel-gateway-api-rules
            groupId: SENTINEL_GROUP
            namespace: ${spring.profiles.active}
            data-type: json
            rule-type: flow
            username: nacos
            password: nacos

四、问题总结

1、Sentinel修改网关配置同步到Nacos?

答案

2、网关服务不能开启配置(spring.cloud.sentinel.eager=true,服务启动直接建立心跳连接),否则网关会变成普通服务。

五、拓展

1、Sentinel持久化到nacos中相关文章推荐

【Sentinel、Nacos】Sentinel中读取Nacos中配置(服务和网关)
【Sentinel、Nacos】Sentinel同步修改到Nacos中
【Sentinel、Nacos】Sentinel同步GateWay网关配置到Nacos中

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值