@@ -135,11 +135,12 @@ | |||||
<version>1.16.1</version> | <version>1.16.1</version> | ||||
<scope>test</scope> | <scope>test</scope> | ||||
</dependency> | </dependency> | ||||
<!--dependency> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | <groupId>org.springframework.boot</groupId> | ||||
<artifactId>spring-boot-configuration-processor</artifactId> | <artifactId>spring-boot-configuration-processor</artifactId> | ||||
<optional>true</optional> | <optional>true</optional> | ||||
</dependency --> | |||||
</dependency> | |||||
</dependencies> | </dependencies> | ||||
<build> | <build> | ||||
@@ -31,10 +31,9 @@ import java.util.List; | |||||
import java.util.Properties; | import java.util.Properties; | ||||
@Configuration | @Configuration | ||||
@EnableConfigurationProperties(NacosConfigurationProperties.class) | |||||
@EnableConfigurationProperties(NacosProperties.class) | |||||
public class NacosConfiguration { | public class NacosConfiguration { | ||||
@Bean | @Bean | ||||
public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() { | public Converter<List<FlowRuleEntity>, String> flowRuleEntityEncoder() { | ||||
return JSON::toJSONString; | return JSON::toJSONString; | ||||
@@ -46,7 +45,7 @@ public class NacosConfiguration { | |||||
} | } | ||||
@Bean | @Bean | ||||
public ConfigService nacosConfiguration(NacosPropertiesConfiguration nacosPropertiesConfiguration) throws NacosException { | |||||
public ConfigService nacosConfiguration(NacosProperties nacosPropertiesConfiguration) throws NacosException { | |||||
Properties properties = new Properties(); | Properties properties = new Properties(); | ||||
properties.put(PropertyKeyConst.SERVER_ADDR,nacosPropertiesConfiguration.getServerAddr()); | properties.put(PropertyKeyConst.SERVER_ADDR,nacosPropertiesConfiguration.getServerAddr()); | ||||
properties.put(PropertyKeyConst.NAMESPACE,nacosPropertiesConfiguration.getNamespace()); | properties.put(PropertyKeyConst.NAMESPACE,nacosPropertiesConfiguration.getNamespace()); | ||||
@@ -15,17 +15,13 @@ | |||||
*/ | */ | ||||
package com.alibaba.csp.sentinel.dashboard.config; | package com.alibaba.csp.sentinel.dashboard.config; | ||||
import org.springframework.beans.factory.annotation.Configurable; | |||||
import org.springframework.boot.context.properties.ConfigurationProperties; | import org.springframework.boot.context.properties.ConfigurationProperties; | ||||
import org.springframework.stereotype.Component; | |||||
/** | /** | ||||
* @author King Wang | * @author King Wang | ||||
*/ | */ | ||||
@Component | |||||
@Configurable | |||||
@ConfigurationProperties(prefix="sentinel.nacos") | @ConfigurationProperties(prefix="sentinel.nacos") | ||||
public class NacosPropertiesConfiguration { | |||||
public class NacosProperties { | |||||
private String serverAddr; | private String serverAddr; | ||||
private String dataId; | private String dataId; |
@@ -16,7 +16,7 @@ | |||||
package com.alibaba.csp.sentinel.dashboard.rule; | package com.alibaba.csp.sentinel.dashboard.rule; | ||||
import com.alibaba.csp.sentinel.dashboard.common.NacosConstants; | 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.dashboard.datasource.entity.rule.FlowRuleEntity; | ||||
import com.alibaba.csp.sentinel.datasource.Converter; | import com.alibaba.csp.sentinel.datasource.Converter; | ||||
import com.alibaba.nacos.api.config.ConfigService; | import com.alibaba.nacos.api.config.ConfigService; | ||||
@@ -37,14 +37,14 @@ public class FlowRuleNacosProvider implements DynamicRuleProvider<List<FlowRuleE | |||||
@Autowired | @Autowired | ||||
private ConfigService configService; | private ConfigService configService; | ||||
@Autowired | @Autowired | ||||
private NacosPropertiesConfiguration nacosPropertiesConfiguration; | |||||
private NacosProperties nacosProperties; | |||||
@Autowired | @Autowired | ||||
private Converter<String, List<FlowRuleEntity>> converter; | private Converter<String, List<FlowRuleEntity>> converter; | ||||
@Override | @Override | ||||
public List<FlowRuleEntity> getRules(String appName) throws Exception { | public List<FlowRuleEntity> getRules(String appName) throws Exception { | ||||
String dataId=new StringBuilder(appName).append(NacosConstants.DATA_ID_POSTFIX).toString(); | 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); | //log.info("pull FlowRule from nacos Config:"+rules); | ||||
if (rules.isEmpty()) { | if (rules.isEmpty()) { | ||||
return new ArrayList<>(); | return new ArrayList<>(); | ||||
@@ -16,7 +16,7 @@ | |||||
package com.alibaba.csp.sentinel.dashboard.rule; | package com.alibaba.csp.sentinel.dashboard.rule; | ||||
import com.alibaba.csp.sentinel.dashboard.common.NacosConstants; | 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.dashboard.datasource.entity.rule.FlowRuleEntity; | ||||
import com.alibaba.csp.sentinel.datasource.Converter; | import com.alibaba.csp.sentinel.datasource.Converter; | ||||
import com.alibaba.csp.sentinel.util.AssertUtil; | import com.alibaba.csp.sentinel.util.AssertUtil; | ||||
@@ -37,7 +37,7 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRul | |||||
@Autowired | @Autowired | ||||
private ConfigService configService; | private ConfigService configService; | ||||
@Autowired | @Autowired | ||||
private NacosPropertiesConfiguration nacosPropertiesConfiguration; | |||||
private NacosProperties nacosProperties; | |||||
@Autowired | @Autowired | ||||
private Converter<List<FlowRuleEntity>,String> converter; | private Converter<List<FlowRuleEntity>,String> converter; | ||||
@@ -49,6 +49,6 @@ public class FlowRuleNacosPublisher implements DynamicRulePublisher<List<FlowRul | |||||
return; | return; | ||||
} | } | ||||
String dataId=new StringBuilder(appName).append(NacosConstants.DATA_ID_POSTFIX).toString(); | 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)); | |||||
} | } | ||||
} | } |