mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
commit
71f8dc0037
@ -193,14 +193,27 @@ 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.
|
||||
|
||||
|
||||
|
||||
When ReadableDataSource load rule data successfully, console will print some logs:
|
||||
|
||||
```
|
||||
[Sentinel Starter] DataSource ds1-sentinel-file-datasource load 3 DegradeRule
|
||||
[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
|
||||
For more information about Sentinel, see [Sentinel Project](https://github.com/alibaba/Sentinel).
|
||||
|
||||
If you have any ideas or suggestions for Spring Cloud Sentinel starter, please don't hesitate to tell us by submitting github issues.
|
||||
If you have any ideas or suggestions for Spring Cloud Sentinel starter, please don't hesitate to tell us by submitting github issues.
|
||||
|
@ -22,6 +22,7 @@ import java.util.Properties;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import com.alibaba.cloud.nacos.diagnostics.analyzer.NacosConnectionFailureException;
|
||||
import com.alibaba.nacos.api.NacosFactory;
|
||||
import com.alibaba.nacos.api.config.ConfigService;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
@ -367,8 +368,8 @@ public class NacosConfigProperties {
|
||||
.createConfigService(getConfigServiceProperties());
|
||||
}
|
||||
catch (NacosException e) {
|
||||
log.error("create naming service error!properties={},e=,", this, e);
|
||||
return null;
|
||||
throw new NacosConnectionFailureException(this.getServerAddr(),
|
||||
e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return configService;
|
||||
|
@ -21,7 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
@ -118,7 +118,7 @@ public abstract class AbstractNacosDataParser {
|
||||
Properties properties = new Properties();
|
||||
for (Map.Entry<String, String> entry : map.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (StringUtils.isBlank(key)) {
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
continue;
|
||||
}
|
||||
key = key.startsWith(DOT) ? key.replaceFirst("\\.", "") : key;
|
||||
|
@ -22,10 +22,11 @@ import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author zkz
|
||||
*/
|
||||
|
@ -25,13 +25,14 @@ import java.util.Properties;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
|
||||
import com.alibaba.nacos.client.utils.StringUtils;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.NamedNodeMap;
|
||||
import org.w3c.dom.Node;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* With relatively few usage scenarios, only simple parsing is performed to reduce jar
|
||||
* dependencies.
|
||||
|
@ -465,7 +465,6 @@ public class NacosDiscoveryProperties {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public NamingService namingServiceInstance() {
|
||||
|
||||
if (null != namingService) {
|
||||
|
@ -66,7 +66,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
@Override
|
||||
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition,
|
||||
Class<?> beanType, String beanName) {
|
||||
if (checkSentinelProtect(beanDefinition, beanType)) {
|
||||
if (checkSentinelProtect(beanDefinition, beanType, beanName)) {
|
||||
SentinelRestTemplate sentinelRestTemplate;
|
||||
if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
|
||||
sentinelRestTemplate = ((StandardMethodMetadata) beanDefinition
|
||||
@ -166,8 +166,8 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
}
|
||||
|
||||
private boolean checkSentinelProtect(RootBeanDefinition beanDefinition,
|
||||
Class<?> beanType) {
|
||||
return beanType == RestTemplate.class
|
||||
Class<?> beanType, String beanName) {
|
||||
return beanName != null && beanType == RestTemplate.class
|
||||
&& checkMethodMetadataReadingVisitor(beanDefinition);
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ public class SentinelBeanPostProcessor implements MergedBeanDefinitionPostProces
|
||||
@Override
|
||||
public Object postProcessAfterInitialization(Object bean, String beanName)
|
||||
throws BeansException {
|
||||
if (cache.containsKey(beanName)) {
|
||||
if (beanName != null && cache.containsKey(beanName)) {
|
||||
// add interceptor for each RestTemplate with @SentinelRestTemplate annotation
|
||||
StringBuilder interceptorBeanNamePrefix = new StringBuilder();
|
||||
SentinelRestTemplate sentinelRestTemplate = cache.get(beanName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user