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

数据源配Apollo不启作用

数据源配到Apollo程序正常运行,但是Apollo中并没有增加相应的配置项。

用了两种 方式 ,但在控制台配置限流后,都没有同步到Apollo中

一种是 :

借助 Sentinel 的 InitFunc SPI 扩展接口。只需要实现自己的 InitFunc 接口,在 init 方法中编写注册数据源的逻辑 运行时日志已显示:

Start 13:35:54.200 [Thread-1] INFO com.ctrip.framework.foundation.internals.provider.DefaultApplicationProvider - App ID is set to d2336a18247739aa by app.id property from System Property 13:35:54.204 [Thread-1] INFO com.ctrip.framework.foundation.internals.provider.DefaultServerProvider - Loading /opt/settings/server.properties 13:35:54.206 [Thread-1] INFO com.ctrip.framework.foundation.internals.provider.DefaultServerProvider - Environment is set to [DEV] by JVM system property 'env'. 13:35:54.206 [Thread-1] INFO com.ctrip.framework.foundation.internals.provider.DefaultServerProvider - Data Center is set to [local] by JVM system property 'idc'. 13:35:54.229 [Thread-1] INFO com.ctrip.framework.apollo.internals.DefaultMetaServerProvider - Located meta services from apollo.meta configuration: http://10.168.100.11:10034! 13:35:54.230 [Thread-1] WARN com.ctrip.framework.apollo.core.utils.ResourceUtils - No available properties: apollo-env.properties 13:35:54.231 [Thread-1] INFO com.ctrip.framework.apollo.core.MetaDomainConsts - Located meta server address http://10.168.100.11:10034 for env DEV from com.ctrip.framework.apollo.internals.DefaultMetaServerProvider End

另一种方式:

创建 ApolloDataSource 并将其注册至对应的 RuleManager 上即可

运行时显示: 13:42:40.323 [main] INFO com.ctrip.framework.foundation.internals.provider.DefaultApplicationProvider - App ID is set to d2336a18247739cd by app.id property from System Property 13:42:40.327 [main] INFO com.ctrip.framework.foundation.internals.provider.DefaultServerProvider - Loading /opt/settings/server.properties 13:42:40.329 [main] INFO com.ctrip.framework.foundation.internals.provider.DefaultServerProvider - Environment is set to [dev] by property 'env' in server.properties. 13:42:40.329 [main] DEBUG com.ctrip.framework.foundation.internals.provider.DefaultServerProvider - Data Center is set to null. Because it is not available in either (1) JVM system property 'idc', (2) OS env variable 'IDC' nor (3) property 'idc' from the properties InputStream. 13:42:40.362 [main] INFO com.ctrip.framework.apollo.internals.DefaultMetaServerProvider - Located meta services from apollo.meta configuration: http://10.168.100.11:10034! 13:42:40.368 [main] WARN com.ctrip.framework.apollo.core.utils.ResourceUtils - No available properties: apollo-env.properties 13:42:40.369 [main] INFO com.ctrip.framework.apollo.core.MetaDomainConsts - Located meta server address http://10.168.100.11:10034 for env DEV from com.ctrip.framework.apollo.internals.DefaultMetaServerProvider 13:42:40.398 [main] DEBUG com.ctrip.framework.apollo.internals.RemoteConfigRepository - Loading config from http://10.168.100.11:10034/configs/d2336a18247739aa/default/application?ip=10.167.3.11 13:42:40.406 [main] DEBUG com.ctrip.framework.apollo.internals.RemoteConfigRepository - Loaded config for application: ApolloConfig{appId='d2336a18247739aa', cluster='default', namespaceName='application', configurations={test.key=test.value}, releaseKey='20190220111333-18b71d03d5d2f0c8'} 13:42:40.407 [main] DEBUG com.ctrip.framework.apollo.internals.RemoteConfigRepository - Remote Config refreshed! 13:42:40.407 [main] DEBUG com.ctrip.framework.apollo.internals.RemoteConfigRepository - Schedule periodic refresh with interval: 5 MINUTES 13:42:40.408 [Apollo-RemoteConfigLongPollService-1] DEBUG com.ctrip.framework.apollo.internals.RemoteConfigLongPollService - Long polling will start in 2000 ms. INFO: log base dir is: /Users/name/logs/csp/ INFO: log name use pid is: false

原提问者GitHub用户188

展开
收起
码字王 2023-05-19 19:04:04 254 0
1 条回答
写回答
取消 提交回答
  • 您必须重构dashboard才能将规则推送到您的配置中心。您可以参考以下指南:

    • 在生产环境中使用 Sentinel

    https://github.com/alibaba/Sentinel/wiki/%E5%9C%A8%E7%94%9F%E4%BA%A7%E7%8E%AF%E5%A2%83%E4%B8%AD%E4%BD%BF%E7%94%A8-Sentinel#push%E6%A8%A1%E5%BC%8F

    • Rule publisher interface and sample in dashboard

    https://github.com/alibaba/Sentinel/wiki/Sentinel-%E6%8E%A7%E5%88%B6%E5%8F%B0%EF%BC%88%E9%9B%86%E7%BE%A4%E6%B5%81%E6%8E%A7%E7%AE%A1%E7%90%86%EF%BC%89#%E8%A7%84%E5%88%99%E9%85%8D%E7%BD%AE

    原回答者GitHub用户sczyh30

    2023-05-19 21:26:57
    赞同 展开评论 打赏
问答分类:
问答地址:

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

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载