DataSourceInitFunc.java 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package com.fdkankan.scene.config;//package com.fdkankan.scene.config;
  2. //
  3. //import com.alibaba.cloud.sentinel.SentinelProperties;
  4. //import com.alibaba.cloud.sentinel.datasource.config.NacosDataSourceProperties;
  5. //import com.alibaba.csp.sentinel.datasource.ReadableDataSource;
  6. //import com.alibaba.csp.sentinel.datasource.nacos.NacosDataSource;
  7. //import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
  8. //import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
  9. //import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
  10. //import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
  11. //import com.alibaba.fastjson.JSON;
  12. //import com.alibaba.fastjson.TypeReference;
  13. //import java.util.List;
  14. //import lombok.extern.slf4j.Slf4j;
  15. //import org.springframework.beans.factory.annotation.Autowired;
  16. //import org.springframework.context.annotation.Bean;
  17. //import org.springframework.context.annotation.Configuration;
  18. //
  19. ///**
  20. // * <p>
  21. // * -
  22. // * </p>
  23. // *
  24. // * @author dengsixing
  25. // * @since 2022/2/14
  26. // **/
  27. //@Configuration
  28. //@Slf4j
  29. //public class DataSourceInitFunc {
  30. //
  31. // @Autowired
  32. // private SentinelProperties sentinelProperties;
  33. //
  34. // @Bean
  35. // public DataSourceInitFunc init() throws Exception {
  36. //
  37. // log.info("[NacosSource初始化,从Nacos中获取熔断规则]");
  38. //
  39. // sentinelProperties.getDatasource().entrySet().stream().filter(map -> {
  40. // return map.getValue().getNacos() != null;
  41. // }).forEach(map -> {
  42. // NacosDataSourceProperties nacos = map.getValue().getNacos();
  43. // // 限流规则,需要Nacos的dataId中包含flow字符串
  44. // if (nacos.getDataId().contains("flow")) {
  45. // ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new NacosDataSource<>(nacos.getServerAddr(),
  46. // nacos.getGroupId(), nacos.getDataId(),
  47. // source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {
  48. // }));
  49. // FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
  50. // }
  51. //
  52. // // 降级规则,需要Nacos的dataId中包含degrade字符串
  53. // if (nacos.getDataId().contains("degrade")) {
  54. // ReadableDataSource<String, List<DegradeRule>> degradeRuleDataSource = new NacosDataSource<>(nacos.getServerAddr(),
  55. // nacos.getGroupId(), nacos.getDataId(),
  56. // source -> JSON.parseObject(source, new TypeReference<List<DegradeRule>>() {
  57. // }));
  58. // DegradeRuleManager.register2Property(degradeRuleDataSource.getProperty());
  59. // }
  60. //
  61. // });
  62. // return new DataSourceInitFunc();
  63. // }
  64. //
  65. //}