mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
71f8dc0037
@ -193,12 +193,25 @@ Now ReadableDataSource type support 5 categories: `file`, `nacos`, `zk`, `apollo
|
|||||||
|
|
||||||
If you want to use `nacos`, `zk`, `apollo` or `redis` ReadableDataSource, you could add `sentinel-datasource-nacos`, `sentinel-datasource-zookeeper`,`sentinel-datasource-apollo` or `sentinel-datasource-redis` dependency.
|
If you want to use `nacos`, `zk`, `apollo` or `redis` ReadableDataSource, you could add `sentinel-datasource-nacos`, `sentinel-datasource-zookeeper`,`sentinel-datasource-apollo` or `sentinel-datasource-redis` dependency.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
When ReadableDataSource load rule data successfully, console will print some logs:
|
When ReadableDataSource load rule data successfully, console will print some logs:
|
||||||
|
|
||||||
```
|
```
|
||||||
[Sentinel Starter] DataSource ds1-sentinel-file-datasource load 3 DegradeRule
|
[Sentinel Starter] DataSource ds1-sentinel-file-datasource load 3 DegradeRule
|
||||||
[Sentinel Starter] DataSource ds2-sentinel-nacos-datasource load 2 FlowRule
|
[Sentinel Starter] DataSource ds2-sentinel-nacos-datasource load 2 FlowRule
|
||||||
```
|
```
|
||||||
|
## Warning
|
||||||
|
You should use `file` ReadableDataSource in a fatjar carefully or you may get error like this below
|
||||||
|
|
||||||
|
```
|
||||||
|
java.lang.RuntimeException: [Sentinel Starter] DataSource ds1 handle file [classpath: flowrule.json] error: class path resource [flowrule.json] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:xxx/xxx.jar!/BOOT-INF/classes!/flowrule.jso
|
||||||
|
```
|
||||||
|
|
||||||
|
You could use absolute path when you use File datasource & fat jar.
|
||||||
|
It is recommended to use Nacos/Apollo/Zookeeper/Redis datasource to store rules.
|
||||||
|
|
||||||
|
https://github.com/alibaba/spring-cloud-alibaba/issues/428
|
||||||
|
|
||||||
## More
|
## More
|
||||||
For more information about Sentinel, see [Sentinel Project](https://github.com/alibaba/Sentinel).
|
For more information about Sentinel, see [Sentinel Project](https://github.com/alibaba/Sentinel).
|
||||||
|
@ -22,6 +22,7 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.nacos.diagnostics.analyzer.NacosConnectionFailureException;
|
||||||
import com.alibaba.nacos.api.NacosFactory;
|
import com.alibaba.nacos.api.NacosFactory;
|
||||||
import com.alibaba.nacos.api.config.ConfigService;
|
import com.alibaba.nacos.api.config.ConfigService;
|
||||||
import com.alibaba.nacos.api.exception.NacosException;
|
import com.alibaba.nacos.api.exception.NacosException;
|
||||||
@ -367,8 +368,8 @@ public class NacosConfigProperties {
|
|||||||
.createConfigService(getConfigServiceProperties());
|
.createConfigService(getConfigServiceProperties());
|
||||||
}
|
}
|
||||||
catch (NacosException e) {
|
catch (NacosException e) {
|
||||||
log.error("create naming service error!properties={},e=,", this, e);
|
throw new NacosConnectionFailureException(this.getServerAddr(),
|
||||||
return null;
|
e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return configService;
|
return configService;
|
||||||
|
@ -21,7 +21,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zkz
|
* @author zkz
|
||||||
@ -118,7 +118,7 @@ public abstract class AbstractNacosDataParser {
|
|||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||||
String key = entry.getKey();
|
String key = entry.getKey();
|
||||||
if (StringUtils.isBlank(key)) {
|
if (StringUtils.isEmpty(key)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
key = key.startsWith(DOT) ? key.replaceFirst("\\.", "") : key;
|
key = key.startsWith(DOT) ? key.replaceFirst("\\.", "") : key;
|
||||||
|
@ -22,10 +22,11 @@ import java.util.Iterator;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zkz
|
* @author zkz
|
||||||
*/
|
*/
|
||||||
|
@ -25,13 +25,14 @@ import java.util.Properties;
|
|||||||
import javax.xml.parsers.DocumentBuilder;
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import com.alibaba.nacos.client.utils.StringUtils;
|
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.NamedNodeMap;
|
import org.w3c.dom.NamedNodeMap;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
import org.w3c.dom.NodeList;
|
import org.w3c.dom.NodeList;
|
||||||
import org.xml.sax.InputSource;
|
import org.xml.sax.InputSource;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* With relatively few usage scenarios, only simple parsing is performed to reduce jar
|
* With relatively few usage scenarios, only simple parsing is performed to reduce jar
|
||||||
* dependencies.
|
* dependencies.
|
||||||
|
@ -465,7 +465,6 @@ public class NacosDiscoveryProperties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public NamingService namingServiceInstance() {
|
public NamingService namingServiceInstance() {
|
||||||
|
|
||||||
if (null != namingService) {
|
if (null != namingService) {
|
||||||
|
@ -66,7 +66,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
@Override
|
@Override
|
||||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
||||||
Class<?> beanType, String beanName) {
|
Class<?> beanType, String beanName) {
|
||||||
if (checkSentinelProtect(beanDefinition, beanType)) {
|
if (checkSentinelProtect(beanDefinition, beanType, beanName)) {
|
||||||
SentinelRestTemplate sentinelRestTemplate;
|
SentinelRestTemplate sentinelRestTemplate;
|
||||||
if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
|
if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
|
||||||
sentinelRestTemplate = ((StandardMethodMetadata) beanDefinition
|
sentinelRestTemplate = ((StandardMethodMetadata) beanDefinition
|
||||||
@ -166,8 +166,8 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
||||||
Class<?> beanType) {
|
Class<?> beanType, String beanName) {
|
||||||
return beanType == RestTemplate.class
|
return beanName != null && beanType == RestTemplate.class
|
||||||
&& checkMethodMetadataReadingVisitor(beanDefinition);
|
&& checkMethodMetadataReadingVisitor(beanDefinition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -180,7 +180,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
|||||||
@Override
|
@Override
|
||||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||||
throws BeansException {
|
throws BeansException {
|
||||||
if (cache.containsKey(beanName)) {
|
if (beanName != null && cache.containsKey(beanName)) {
|
||||||
// add interceptor for each RestTemplate with @SentinelRestTemplate annotation
|
// add interceptor for each RestTemplate with @SentinelRestTemplate annotation
|
||||||
StringBuilder interceptorBeanNamePrefix = new StringBuilder();
|
StringBuilder interceptorBeanNamePrefix = new StringBuilder();
|
||||||
SentinelRestTemplate sentinelRestTemplate = cache.get(beanName);
|
SentinelRestTemplate sentinelRestTemplate = cache.get(beanName);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user