0
点赞
收藏
分享

微信扫一扫

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

爱动漫建模 2022-03-12 阅读 70

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

二、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,服务启动直接建立心跳连接),否则网关会变成普通服务。

举报

相关推荐

0 条评论