mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #1318 from mengjincn/mengjincn
✨ Introducing new features. Sentinel Support ConsulDataSource Dynamic Rule Configuration
This commit is contained in:
commit
a3299d529a
@ -84,6 +84,12 @@
|
|||||||
<version>${sentinel.version}</version>
|
<version>${sentinel.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-datasource-consul</artifactId>
|
||||||
|
<version>${sentinel.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.csp</groupId>
|
<groupId>com.alibaba.csp</groupId>
|
||||||
<artifactId>sentinel-web-servlet</artifactId>
|
<artifactId>sentinel-web-servlet</artifactId>
|
||||||
|
@ -83,6 +83,12 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba.csp</groupId>
|
||||||
|
<artifactId>sentinel-datasource-consul</artifactId>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.sentinel.datasource.config;
|
||||||
|
|
||||||
|
import com.alibaba.cloud.sentinel.datasource.factorybean.ConsulDataSourceFactoryBean;
|
||||||
|
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consul Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||||
|
* {@link ConsulDataSourceFactoryBean}.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:mengjindc@gmail.com">mengjin</a>
|
||||||
|
*/
|
||||||
|
public class ConsulDataSourceProperties extends AbstractDataSourceProperties {
|
||||||
|
|
||||||
|
public ConsulDataSourceProperties(){
|
||||||
|
super(ConsulDataSourceFactoryBean.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* consul server host.
|
||||||
|
*/
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* consul server port.
|
||||||
|
*/
|
||||||
|
private int port=8500;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* data key in Redis.
|
||||||
|
*/
|
||||||
|
private String ruleKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request of query will hang until timeout (in second) or get updated value.
|
||||||
|
*/
|
||||||
|
private int waitTimeoutInSecond = 1;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void preCheck(String dataSourceName) {
|
||||||
|
if(StringUtils.isEmpty(host)){
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"ConsulDataSource server-host is empty");
|
||||||
|
}
|
||||||
|
if(StringUtils.isEmpty(ruleKey)){
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"ConsulDataSource ruleKey can not be empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleKey() {
|
||||||
|
return ruleKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuleKey(String ruleKey) {
|
||||||
|
this.ruleKey = ruleKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWaitTimeoutInSecond() {
|
||||||
|
return waitTimeoutInSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
||||||
|
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
* @see ZookeeperDataSourceProperties
|
* @see ZookeeperDataSourceProperties
|
||||||
* @see FileDataSourceProperties
|
* @see FileDataSourceProperties
|
||||||
* @see RedisDataSourceProperties
|
* @see RedisDataSourceProperties
|
||||||
|
* @see ConsulDataSourceProperties
|
||||||
*/
|
*/
|
||||||
public class DataSourcePropertiesConfiguration {
|
public class DataSourcePropertiesConfiguration {
|
||||||
|
|
||||||
@ -47,9 +48,23 @@ public class DataSourcePropertiesConfiguration {
|
|||||||
|
|
||||||
private RedisDataSourceProperties redis;
|
private RedisDataSourceProperties redis;
|
||||||
|
|
||||||
|
private ConsulDataSourceProperties consul;
|
||||||
|
|
||||||
public DataSourcePropertiesConfiguration() {
|
public DataSourcePropertiesConfiguration() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DataSourcePropertiesConfiguration(ConsulDataSourceProperties consul) {
|
||||||
|
this.consul = consul;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConsulDataSourceProperties getConsul() {
|
||||||
|
return consul;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsul(ConsulDataSourceProperties consul) {
|
||||||
|
this.consul = consul;
|
||||||
|
}
|
||||||
|
|
||||||
public DataSourcePropertiesConfiguration(FileDataSourceProperties file) {
|
public DataSourcePropertiesConfiguration(FileDataSourceProperties file) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import com.alibaba.cloud.sentinel.datasource.factorybean.RedisDataSourceFactoryB
|
|||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zookeeper Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
* Redis Properties class Using by {@link DataSourcePropertiesConfiguration} and
|
||||||
* {@link RedisDataSourceFactoryBean}.
|
* {@link RedisDataSourceFactoryBean}.
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:wangiegie@gmail.com">lengleng</a>
|
* @author <a href="mailto:wangiegie@gmail.com">lengleng</a>
|
||||||
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2013-2018 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.alibaba.cloud.sentinel.datasource.factorybean;
|
||||||
|
|
||||||
|
import com.alibaba.csp.sentinel.datasource.Converter;
|
||||||
|
import com.alibaba.csp.sentinel.datasource.consul.ConsulDataSource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.FactoryBean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A {@link FactoryBean} for creating {@link ConsulDataSource} instance.
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:mengjindc@gmail.com">mengjin</a>
|
||||||
|
* @see ConsulDataSource
|
||||||
|
*/
|
||||||
|
public class ConsulDataSourceFactoryBean implements FactoryBean<ConsulDataSource> {
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
private String ruleKey;
|
||||||
|
|
||||||
|
private int waitTimeoutInSecond;
|
||||||
|
|
||||||
|
private Converter converter;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConsulDataSource getObject() throws Exception {
|
||||||
|
return new ConsulDataSource(
|
||||||
|
host,
|
||||||
|
port,
|
||||||
|
ruleKey,
|
||||||
|
waitTimeoutInSecond,
|
||||||
|
converter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> getObjectType() {
|
||||||
|
return ConsulDataSource.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRuleKey() {
|
||||||
|
return ruleKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRuleKey(String ruleKey) {
|
||||||
|
this.ruleKey = ruleKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWaitTimeoutInSecond() {
|
||||||
|
return waitTimeoutInSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWaitTimeoutInSecond(int waitTimeoutInSecond) {
|
||||||
|
this.waitTimeoutInSecond = waitTimeoutInSecond;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Converter getConverter() {
|
||||||
|
return converter;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConverter(Converter converter) {
|
||||||
|
this.converter = converter;
|
||||||
|
}
|
||||||
|
}
|
@ -3,3 +3,4 @@ file =com.alibaba.csp.sentinel.datasource.FileRefreshableDataSource
|
|||||||
apollo = com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource
|
apollo = com.alibaba.csp.sentinel.datasource.apollo.ApolloDataSource
|
||||||
zk = com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource
|
zk = com.alibaba.csp.sentinel.datasource.zookeeper.ZookeeperDataSource
|
||||||
redis = com.alibaba.csp.sentinel.datasource.redis.RedisDataSource
|
redis = com.alibaba.csp.sentinel.datasource.redis.RedisDataSource
|
||||||
|
consul = com.alibaba.csp.sentinel.datasource.consul.ConsulDataSource
|
||||||
|
Loading…
x
Reference in New Issue
Block a user