alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.95k stars 8.34k forks source link

使用 spring-cloud-starter-alibaba-sentinel 集群模式下不能按照集群限流 #1676

Open tangchen-blip opened 4 years ago

tangchen-blip commented 4 years ago

依赖:

org.springframework.cloud spring-cloud-starter-alibaba-sentinel 0.9.0.RELEASE
    <!-- 用于查看Sentinel客户端相关规则 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <!--sentinel指定nacos为数据源 -->
    <dependency>
        <groupId>com.alibaba.csp</groupId>
        <artifactId>sentinel-datasource-nacos</artifactId>
        <version>1.7.0</version>
    </dependency>

问题: 在单机模式下能够正常限流 在集群模式下 配置总qps 1 但是能够同时访问两次 通过跟踪 发现在注册token server 时监听器里面没有获取到限流规则 通过自定义InitFuc给集群模式注入NacosDataSource才能正常限流,请问有其他的方式能够实现吗 单机并不需要配自定义InitFuc 代码

@Override

public void init() {
    Properties properties=new Properties();
    properties.put("serverAddr","101.133.156.253:8848");
    properties.put("namespace","compile");
    ClusterFlowRuleManager.setPropertySupplier(namespace -> {
        ReadableDataSource<String, List<FlowRule>> ds = new NacosDataSource<>(properties, "cqz",
               "user-provider-flow-rules", source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {}));
        return ds.getProperty();
    });
    // Register cluster parameter flow rule property supplier which creates data source by namespace.
    ClusterParamFlowRuleManager.setPropertySupplier(namespace -> {
        ReadableDataSource<String, List<ParamFlowRule>> ds = new NacosDataSource<>(properties,"cqz",
                "user-provider-flow-rules", source -> JSON.parseObject(source, new TypeReference<List<ParamFlowRule>>() {}));
        return ds.getProperty();
    });
}

配置文件

spring: cloud: sentinel: eager: true transport: dashboard: localhost:8080 heartbeat-interval-ms: 500 port: 8719 datasource: ds2: nacos: server-addr: xxxxxxx:8848 dataId: user-provider-flow-rules groupId: cqz data-type: json namespace: compile rule-type: flow

yuhuangbin commented 4 years ago

建议使用spring cloud alibaba 毕业版本再次尝试。非毕业版本不提供维护了。

tangchen-blip commented 4 years ago

也不行 只作用于单机 采用的是内嵌的方式

tangchen-blip commented 4 years ago

版本号 2.1.1 sentinel 1.7

wanghuajian122 commented 2 years ago

这个问题最后有解决吗?我也遇到过同样的问题

leeroy-code commented 2 years ago

解决了吗?

1113126226 commented 2 years ago

解决了吗

leeroy-code commented 2 years ago

集群模式,需要改源码的