소스 검색

nacos持久化

master
wangjx 3 년 전
부모
커밋
e31a2beca4
5개의 변경된 파일12개의 추가작업 그리고 16개의 파일을 삭제
  1. +3
    -2
      sentinel-dashboard/pom.xml
  2. +2
    -3
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosConfiguration.java
  3. +1
    -5
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosProperties.java
  4. +3
    -3
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java
  5. +3
    -3
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java

+ 3
- 2
sentinel-dashboard/pom.xml 파일 보기

@@ -135,11 +135,12 @@
<version>1.16.1</version>
<scope>test</scope>
</dependency>
<!--dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency -->
</dependency>
</dependencies>

<build>


+ 2
- 3
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosConfiguration.java 파일 보기

@@ -31,10 +31,9 @@ import java.util.List;
import java.util.Properties;

@Configuration
@EnableConfigurationProperties(NacosConfigurationProperties.class)
@EnableConfigurationProperties(NacosProperties.class)
public class NacosConfiguration {


@Bean
public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() {
return JSON::toJSONString;
@@ -46,7 +45,7 @@ public class NacosConfiguration {
}

@Bean
public ConfigService nacosConfiguration(NacosPropertiesConfiguration nacosPropertiesConfiguration) throws NacosException {
public ConfigService nacosConfiguration(NacosProperties nacosPropertiesConfiguration) throws NacosException {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR,nacosPropertiesConfiguration.getServerAddr());
properties.put(PropertyKeyConst.NAMESPACE,nacosPropertiesConfiguration.getNamespace());


sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosPropertiesConfiguration.java → sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/config/NacosProperties.java 파일 보기

@@ -15,17 +15,13 @@
*/
package com.alibaba.csp.sentinel.dashboard.config;

import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
* @author King Wang
*/
@Component
@Configurable
@ConfigurationProperties(prefix="sentinel.nacos")
public class NacosPropertiesConfiguration {
public class NacosProperties {

private String serverAddr;
private String dataId;

+ 3
- 3
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosProvider.java 파일 보기

@@ -16,7 +16,7 @@
package com.alibaba.csp.sentinel.dashboard.rule;

import com.alibaba.csp.sentinel.dashboard.common.NacosConstants;
import com.alibaba.csp.sentinel.dashboard.config.NacosPropertiesConfiguration;
import com.alibaba.csp.sentinel.dashboard.config.NacosProperties;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.nacos.api.config.ConfigService;
@@ -37,14 +37,14 @@ public class FlowRuleNacosProvider implements DynamicRuleProvider<List<FlowRuleE
@Autowired
private ConfigService configService;
@Autowired
private NacosPropertiesConfiguration nacosPropertiesConfiguration;
private NacosProperties nacosProperties;
@Autowired
private Converter<String, List<FlowRuleEntity>> converter;

@Override
public List<FlowRuleEntity> getRules(String appName) throws Exception {
String dataId=new StringBuilder(appName).append(NacosConstants.DATA_ID_POSTFIX).toString();
String rules = configService.getConfig(dataId,nacosPropertiesConfiguration.getGroupId(),3000);
String rules = configService.getConfig(dataId,nacosProperties.getGroupId(),3000);
//log.info("pull FlowRule from nacos Config:"+rules);
if (rules.isEmpty()) {
return new ArrayList<>();


+ 3
- 3
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/rule/FlowRuleNacosPublisher.java 파일 보기

@@ -16,7 +16,7 @@
package com.alibaba.csp.sentinel.dashboard.rule;

import com.alibaba.csp.sentinel.dashboard.common.NacosConstants;
import com.alibaba.csp.sentinel.dashboard.config.NacosPropertiesConfiguration;
import com.alibaba.csp.sentinel.dashboard.config.NacosProperties;
import com.alibaba.csp.sentinel.dashboard.datasource.entity.rule.FlowRuleEntity;
import com.alibaba.csp.sentinel.datasource.Converter;
import com.alibaba.csp.sentinel.util.AssertUtil;
@@ -37,7 +37,7 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRul
@Autowired
private ConfigService configService;
@Autowired
private NacosPropertiesConfiguration nacosPropertiesConfiguration;
private NacosProperties nacosProperties;
@Autowired
private Converter<List<FlowRuleEntity>,String> converter;

@@ -49,6 +49,6 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRul
return;
}
String dataId=new StringBuilder(appName).append(NacosConstants.DATA_ID_POSTFIX).toString();
configService.publishConfig(dataId,nacosPropertiesConfiguration.getGroupId(),converter.convert(rules));
configService.publishConfig(dataId,nacosProperties.getGroupId(),converter.convert(rules));
}
}

Loading…
취소
저장