开发者社区 > 云原生 > 正文

使用Spring Cloud Alibaba Sentinel与Nacos转换流量规则失败

nacos收到的流控规则如下:

[{"app":"service-consumer","clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCount":10,"strategy":0,"thresholdType":0,"windowIntervalMs":1000},"clusterMode":false,"controlBehavior":0,"count":1.0,"gmtCreate":1573130440602,"gmtModified":1573130440602,"grade":1,"id":1,"ip":"172.18.54.192","limitApp":"default","port":8720,"resource":"/hello","strategy":0}]

服务启动异常,规则无法生效:

java.lang.RuntimeException: convert error: convert 0 rules but there are 1 rules from datasource. RuleClass: FlowRule at org.springframework.cloud.alibaba.sentinel.datasource.converter.SentinelConverter.convert(SentinelConverter.java:84) ~[spring-cloud-alibaba-sentinel-datasource-0.9.0.RELEASE.jar:0.9.0.RELEASE] at org.springframework.cloud.alibaba.sentinel.datasource.converter.SentinelConverter.convert(SentinelConverter.java:37) ~[spring-cloud-alibaba-sentinel-datasource-0.9.0.RELEASE.jar:0.9.0.RELEASE] at com.alibaba.csp.sentinel.datasource.AbstractDataSource.loadConfig(AbstractDataSource.java:48) ~[sentinel-datasource-extension-1.6.3.jar:na] at com.alibaba.csp.sentinel.datasource.AbstractDataSource.loadConfig(AbstractDataSource.java:44) ~[sentinel-datasource-extension-1.6.3.jar:na] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.logAndCheckRuleType(SentinelDataSourceHandler.java:195) [spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.registerBean(SentinelDataSourceHandler.java:184) [spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.lambda$afterSingletonsInstantiated$0(SentinelDataSourceHandler.java:72) [spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at java.util.TreeMap.forEach(TreeMap.java:1005) ~[na:1.8.0_111] at org.springframework.cloud.alibaba.sentinel.custom.SentinelDataSourceHandler.afterSingletonsInstantiated(SentinelDataSourceHandler.java:60) [spring-cloud-alibaba-sentinel-0.9.0.RELEASE.jar:0.9.0.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:864) ~[spring-beans-5.1.10.RELEASE.jar:5.1.10.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.10.RELEASE.jar:5.1.10.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.10.RELEASE.jar:5.1.10.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:744) ~[spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:391) ~[spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:312) ~[spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204) ~[spring-boot-2.1.9.RELEASE.jar:2.1.9.RELEASE] at com.example.demo.DemoApplication.main(DemoApplication.java:15) ~[classes/:na] Caused by: java.lang.IllegalArgumentException: convert 0 rules but there are 1 rules from datasource. RuleClass: FlowRule at org.springframework.cloud.alibaba.sentinel.datasource.converter.SentinelConverter.convert(SentinelConverter.java:80) ~[spring-cloud-alibaba-sentinel-datasource-0.9.0.RELEASE.jar:0.9.0.RELEASE] ... 18 common frames omitted

尝试将服务组件都升级到最新版本也无法解决问题

通过sentinel源码手动编写json属性过滤器 可以临时解决问题

原提问者GitHub用户liupanjjjj

展开
收起
码字王 2023-05-19 16:58:11 123 0
1 条回答
写回答
取消 提交回答
  • 2.1.0.版本可以解决这个问题。

    https://github.com/alibaba/spring-cloud-alibaba/issues/569

    原回答者GitHub用户fangjian0423

    2023-05-19 22:44:00
    赞同 展开评论 打赏

阿里云拥有国内全面的云原生产品技术以及大规模的云原生应用实践,通过全面容器化、核心技术互联网化、应用 Serverless 化三大范式,助力制造业企业高效上云,实现系统稳定、应用敏捷智能。拥抱云原生,让创新无处不在。

相关电子书

更多
阿里云容器 AHAS Sentinel 网关流控揭秘 立即下载
workshop专场-微服务专场-开发者动手实践营-微服务-使用Nacos进行服务的动态发现和流量调度 立即下载
Nacos 启航,发布第一个版本, 云原生时代助力用户微服务平台建设 立即下载