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

使用fastjson1.2.7解析流规则时,资源字段将丢失

最近在尝试sentinel的限流,并接入的apollo配置中心。

在编码测试过程中发现,已经能从配置中心获取到更新的配置数据。但是dashboard查询client端的限流规则时没有数据,并且限流规则也没有生效。于是debug跟了下代码发现。apollo数据变更监听拿到的数据是对的,只是在ApolloDataSource里面利用fastjson去解析成FlowRule对象的时候对象里面的resource被解析成了null。 于是对比了github的demo发现fastjson版本不一样。于是替换成同demo一样的1.2.55果然问题就没有了。暂时不清楚是否是fastjson1.2.7的bug还是sentinel自身bug。

因为公司本身项目中目前fastjson版本为1.2.7.如问题不能很好解决后期在推动sentinel应用过程中需要接入项目全部调整fastjson版本。不知道这个问题是否已经解决或者有更优处理方案。

以下是部分sentile-recode日志记录的: <2019-04-18 15:15:51 Receiving rule change (type: flow): [{"clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCount":10,"strategy":0,"thresholdType":0,"windowIntervalMs":1000},"clusterMode":false,"controlBehavior":0,"count":3.0,"grade":1,"limitApp":"default","maxQueueingTimeMs":500,"resource":"/test","strategy":0,"warmUpPeriodSec":10},{"clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCount":10,"strategy":0,"thresholdType":0,"windowIntervalMs":1000},"clusterMode":false,"controlBehavior":0,"count":1.0,"grade":1,"limitApp":"default","maxQueueingTimeMs":500,"resource":"/v2/user/isExisted","strategy":0,"warmUpPeriodSec":10},{"clusterConfig":{"fallbackToLocalWhenFail":true,"sampleCount":10,"strategy":0,"thresholdType":0,"windowIntervalMs":1000},"clusterMode":false,"controlBehavior":0,"count":2.0,"grade":1,"limitApp":"default","maxQueueingTimeMs":500,"resource":"/v2/user/test","strategy":0,"warmUpPeriodSec":10}] 2019-04-18 15:15:51 [DynamicSentinelProperty] Config will be updated to: [FlowRule{resource=null, limitApp=default, grade=1, count=3.0, strategy=0, refResource=null, controlBehavior=0, warmUpPeriodSec=10, maxQueueingTimeMs=500, clusterMode=false, clusterConfig=ClusterFlowConfig{flowId=null, thresholdType=0, fallbackToLocalWhenFail=true, strategy=0, sampleCount=10, windowIntervalMs=1000}, controller=null}, FlowRule{resource=null, limitApp=default, grade=1, count=1.0, strategy=0, refResource=null, controlBehavior=0, warmUpPeriodSec=10, maxQueueingTimeMs=500, clusterMode=false, clusterConfig=ClusterFlowConfig{flowId=null, thresholdType=0, fallbackToLocalWhenFail=true, strategy=0, sampleCount=10, windowIntervalMs=1000}, controller=null}, FlowRule{resource=null, limitApp=default, grade=1, count=2.0, strategy=0, refResource=null, controlBehavior=0, warmUpPeriodSec=10, maxQueueingTimeMs=500, clusterMode=false, clusterConfig=ClusterFlowConfig{flowId=null, thresholdType=0, fallbackToLocalWhenFail=true, strategy=0, sampleCount=10, windowIntervalMs=1000}, controller=null}] 2019-04-18 15:15:51 [FlowRuleManager] Ignoring invalid flow rule when loading new flow rules: FlowRule{resource=null, limitApp=default, grade=1, count=3.0, strategy=0, refResource=null, controlBehavior=0, warmUpPeriodSec=10, maxQueueingTimeMs=500, clusterMode=false, clusterConfig=ClusterFlowConfig{flowId=null, thresholdType=0, fallbackToLocalWhenFail=true, strategy=0, sampleCount=10, windowIntervalMs=1000}, controller=null} 2019-04-18 15:15:51 [FlowRuleManager] Ignoring invalid flow rule when loading new flow rules: FlowRule{resource=null, limitApp=default, grade=1, count=1.0, strategy=0, refResource=null, controlBehavior=0, warmUpPeriodSec=10, maxQueueingTimeMs=500, clusterMode=false, clusterConfig=ClusterFlowConfig{flowId=null, thresholdType=0, fallbackToLocalWhenFail=true, strategy=0, sampleCount=10, windowIntervalMs=1000}, controller=null} 2019-04-18 15:15:51 [FlowRuleManager] Ignoring invalid flow rule when loading new flow rules: FlowRule{resource=null, limitApp=default, grade=1, count=2.0, strategy=0, refResource=null, controlBehavior=0, warmUpPeriodSec=10, maxQueueingTimeMs=500, clusterMode=false, clusterConfig=ClusterFlowConfig{flowId=null, thresholdType=0, fallbackToLocalWhenFail=true, strategy=0, sampleCount=10, windowIntervalMs=1000}, controller=null}

原提问者GitHub用户haoleng

展开
收起
码字王 2023-05-19 18:49:39 1341 0
1 条回答
写回答
取消 提交回答
  • 这是一个已知的问题。不推荐也不支持旧版本的fastjson。您需要将fastjson升级到最新版本。

    原回答者GitHub用户sczyh30

    2023-05-19 21:28:06
    赞同 展开评论 打赏

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

相关电子书

更多
神龙云服务器产品及技术深度解析 立即下载
弹性创造价值:基于ECS的最佳性价比实践解析 立即下载
又快又稳:阿里云下一代虚拟交换机解析 立即下载

相关镜像