@@ -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> | |||
@@ -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()); | |||
@@ -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; |
@@ -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<>(); | |||
@@ -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)); | |||
} | |||
} |