mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Compare commits
49 Commits
2.2.1.RELEASE
..
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| f9f3bd8a54 | |||
| f6fb6890b9 | |||
| 940420b0bf | |||
| f2f58b90a0 | |||
| bc657f6677 | |||
| 04c0680e33 | |||
| 5de5d9d386 | |||
| 93cb226850 | |||
| 5078f355ca | |||
| 7667a05aef | |||
| 3af1b5c51c | |||
| bfbb680f6b | |||
| 1e74332a0a | |||
| aaccfbf929 | |||
| 7b42a9a31e | |||
| ec06f97aa0 | |||
| 0a89ad61e1 | |||
| 1ced8d231b | |||
| eff43225d6 | |||
| 6411a24719 | |||
| 213bf2a912 | |||
| 8a68526da7 | |||
| 9737f0dfbb | |||
| 2a643c82bf | |||
| 83800b23b6 | |||
| 1a163b1b85 | |||
| 28c9e630cb | |||
| a88bd7008e | |||
| 5d462252f5 | |||
| a1c140ba8a | |||
| cb9b61f2b8 | |||
| 2e934f09e9 | |||
| c7ea46301f | |||
| 2373f71005 | |||
| 3ecae6f35d | |||
| 593433502d | |||
| 9831e9b69b | |||
| d11a922cf2 | |||
| fd92414609 | |||
| 432f3e3e05 | |||
| fd58f75e41 | |||
| db9bd28fb4 | |||
| 0c39f71316 | |||
| 71eb9ef06a | |||
| 2600e42f51 | |||
| 19b98263cd | |||
| 8991078055 | |||
| cb27412021 | |||
| 6295537007 |
@@ -71,7 +71,7 @@ These artifacts are available from Maven Central and Spring Release repository v
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>2.2.0.RELEASE</version>
|
||||
<version>2.2.1.RELEASE</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -349,6 +349,31 @@
|
||||
<reuseForks>false</reuseForks>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>${flatten-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -406,32 +431,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>flatten-maven-plugin</artifactId>
|
||||
<version>${flatten-maven-plugin.version}</version>
|
||||
<configuration>
|
||||
<updatePomFile>true</updatePomFile>
|
||||
<flattenMode>resolveCiFriendliesOnly</flattenMode>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>flatten</id>
|
||||
<phase>process-resources</phase>
|
||||
<goals>
|
||||
<goal>flatten</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>flatten.clean</id>
|
||||
<phase>clean</phase>
|
||||
<goals>
|
||||
<goal>clean</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
|
||||
<properties>
|
||||
<revision>2.2.1.RELEASE</revision>
|
||||
<sentinel.version>1.7.1</sentinel.version>
|
||||
<sentinel.version>1.7.2</sentinel.version>
|
||||
<oss.version>3.1.0</oss.version>
|
||||
<seata.version>1.1.0</seata.version>
|
||||
<seata.version>1.2.0</seata.version>
|
||||
<nacos.client.version>1.2.1</nacos.client.version>
|
||||
<nacos.config.version>0.8.0</nacos.config.version>
|
||||
<spring.context.support.version>1.0.6</spring.context.support.version>
|
||||
|
||||
@@ -415,8 +415,8 @@ Endpoint 暴露的 json 中包含了三种属性:
|
||||
|===
|
||||
|配置项 |Key |默认值 |说明
|
||||
|服务端地址|`spring.cloud.nacos.config.server-addr`|| Nacos Server 启动监听的ip地址和端口
|
||||
|配置对应的 DataId|`spring.cloud.nacos.config.name`|| 先取 prefix,再去 name,最后取 spring.application.name
|
||||
|配置对应的 DataId|`spring.cloud.nacos.config.prefix`|| 先取 prefix,再去 name,最后取 spring.application.name
|
||||
|配置对应的 DataId|`spring.cloud.nacos.config.name`|| 先取 prefix,再取 name,最后取 spring.application.name
|
||||
|配置对应的 DataId|`spring.cloud.nacos.config.prefix`|| 先取 prefix,再取 name,最后取 spring.application.name
|
||||
|配置内容编码|`spring.cloud.nacos.config.encode`||读取的配置内容对应的编码
|
||||
|GROUP|`spring.cloud.nacos.config.group`|`DEFAULT_GROUP`|配置对应的组
|
||||
|文件扩展名|`spring.cloud.nacos.config.fileExtension`|`properties`|配置项对应的文件扩展名,目前支持 properties 和 yaml(yml)
|
||||
|
||||
@@ -175,7 +175,7 @@ AccessKey|spring.cloud.nacos.config.access-key||
|
||||
SecretKey|spring.cloud.nacos.config.secret-key||
|
||||
相对路径|spring.cloud.nacos.config.context-path||服务端 API 的相对路径
|
||||
接入点|spring.cloud.nacos.config.endpoint|UTF-8|地域的某个服务的入口域名,通过此域名可以动态地拿到服务端地址
|
||||
是否开启监听和自动刷新|spring.cloud.nacos.config.refresh.enabled|true|
|
||||
是否开启监听和自动刷新|spring.cloud.nacos.config.refresh-enabled|true|
|
||||
|
||||
|
||||
|
||||
|
||||
+1
@@ -1,6 +1,7 @@
|
||||
server.port=18082
|
||||
spring.application.name=service-provider
|
||||
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
|
||||
#spring.cloud.nacos.discovery.instance-enabled=true
|
||||
|
||||
spring.cloud.nacos.username=nacos
|
||||
spring.cloud.nacos.password=nacos
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
public class ProviderApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
SpringApplication.run(ProviderApplication.class, args);
|
||||
}
|
||||
|
||||
@RestController
|
||||
|
||||
@@ -29,7 +29,7 @@ Before we start the demo, let's learn how to connect Nacos Config to a Spring Cl
|
||||
public class ProviderApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
SpringApplication.run(ProviderApplication.class, args);
|
||||
}
|
||||
|
||||
@RestController
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
<artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-sentinel-datasource</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
@@ -36,10 +41,10 @@
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.alibaba.csp</groupId>-->
|
||||
<!--<artifactId>sentinel-datasource-nacos</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.csp</groupId>
|
||||
<artifactId>sentinel-datasource-nacos</artifactId>
|
||||
</dependency>
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.alibaba.csp</groupId>-->
|
||||
<!--<artifactId>sentinel-datasource-zookeeper</artifactId>-->
|
||||
|
||||
+8
@@ -9,11 +9,19 @@ management.health.diskspace.enabled=false
|
||||
|
||||
spring.cloud.sentinel.transport.dashboard=localhost:8080
|
||||
spring.cloud.sentinel.eager=true
|
||||
spring.cloud.sentinel.web-context-unify=true
|
||||
|
||||
#spring.cloud.sentinel.block-page=/errorPage
|
||||
#spring.cloud.sentinel.filter.enabled=false
|
||||
#spring.cloud.sentinel.http-method-specify=false
|
||||
|
||||
#spring.cloud.sentinel.datasource.ds6.nacos.server-addr=127.0.0.1:8848
|
||||
#spring.cloud.sentinel.datasource.ds6.nacos.username=nacos
|
||||
#spring.cloud.sentinel.datasource.ds6.nacos.password=nacos
|
||||
#spring.cloud.sentinel.datasource.ds6.nacos.dataId=flowrule.json
|
||||
#spring.cloud.sentinel.datasource.ds6.nacos.data-type=json
|
||||
#spring.cloud.sentinel.datasource.ds6.nacos.rule-type=flow
|
||||
|
||||
spring.cloud.sentinel.datasource.ds1.file.file=classpath: flowrule.json
|
||||
spring.cloud.sentinel.datasource.ds1.file.data-type=json
|
||||
spring.cloud.sentinel.datasource.ds1.file.rule-type=flow
|
||||
|
||||
+1
@@ -33,6 +33,7 @@ spring:
|
||||
enabled: true
|
||||
register-enabled: true
|
||||
server-addr: 127.0.0.1:8848
|
||||
ephemeral: false
|
||||
|
||||
|
||||
---
|
||||
|
||||
+3
-6
@@ -20,9 +20,10 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-gateway</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -33,10 +34,6 @@
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
+4
-1
@@ -6,11 +6,13 @@ spring:
|
||||
username: nacos
|
||||
password: nacos
|
||||
discovery:
|
||||
server-addr: localhost:8848
|
||||
server-addr: 127.0.0.1:8848
|
||||
group: test
|
||||
gateway:
|
||||
discovery:
|
||||
locator:
|
||||
enabled: true
|
||||
|
||||
application:
|
||||
name: node-service
|
||||
sidecar:
|
||||
@@ -18,6 +20,7 @@ sidecar:
|
||||
ip: 127.0.0.1
|
||||
# 异构微服务的端口
|
||||
port: 8060
|
||||
|
||||
# 异构微服务的健康检查URL
|
||||
#health-check-url: http://localhost:8060/health.json
|
||||
management:
|
||||
|
||||
+20
@@ -32,6 +32,10 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
|
||||
private String serverAddr;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
@NotEmpty
|
||||
private String groupId = "DEFAULT_GROUP";
|
||||
|
||||
@@ -67,6 +71,22 @@ public class NacosDataSourceProperties extends AbstractDataSourceProperties {
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
+22
@@ -35,6 +35,10 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
|
||||
private String serverAddr;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String groupId;
|
||||
|
||||
private String dataId;
|
||||
@@ -63,6 +67,8 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
if (!StringUtils.isEmpty(this.namespace)) {
|
||||
properties.setProperty(PropertyKeyConst.NAMESPACE, this.namespace);
|
||||
}
|
||||
properties.setProperty(PropertyKeyConst.USERNAME, this.username);
|
||||
properties.setProperty(PropertyKeyConst.PASSWORD, this.password);
|
||||
return new NacosDataSource(properties, groupId, dataId, converter);
|
||||
}
|
||||
|
||||
@@ -79,6 +85,22 @@ public class NacosDataSourceFactoryBean implements FactoryBean<NacosDataSource>
|
||||
this.serverAddr = serverAddr;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
+3
-1
@@ -55,7 +55,9 @@ public class NacosDataPropertiesParser extends AbstractNacosDataParser {
|
||||
log.warn("the config data is invalid {}", dataLine);
|
||||
continue;
|
||||
}
|
||||
result.put(dataLine.substring(0, index), dataLine.substring(index + 1));
|
||||
String key = dataLine.substring(0, index);
|
||||
String value = dataLine.substring(index + 1);
|
||||
result.put(key.trim(), value.trim());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
+28
-1
@@ -64,8 +64,8 @@ import static com.alibaba.nacos.api.PropertyKeyConst.USERNAME;
|
||||
* @author xiaojing
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @author <a href="mailto:lyuzb@lyuzb.com">lyuzb</a>
|
||||
* @author <a href="mailto:78552423@qq.com">eshun</a>
|
||||
*/
|
||||
|
||||
@ConfigurationProperties("spring.cloud.nacos.discovery")
|
||||
public class NacosDiscoveryProperties {
|
||||
|
||||
@@ -199,6 +199,16 @@ public class NacosDiscoveryProperties {
|
||||
*/
|
||||
private Integer ipDeleteTimeout;
|
||||
|
||||
/**
|
||||
* If instance is enabled to accept request. The default value is true.
|
||||
*/
|
||||
private boolean instanceEnabled = true;
|
||||
|
||||
/**
|
||||
* If instance is ephemeral.The default value is true.
|
||||
*/
|
||||
private boolean ephemeral = true;
|
||||
|
||||
@Autowired
|
||||
private InetUtils inetUtils;
|
||||
|
||||
@@ -211,6 +221,7 @@ public class NacosDiscoveryProperties {
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws SocketException {
|
||||
namingService = null;
|
||||
|
||||
metadata.put(PreservedMetadataKeys.REGISTER_SOURCE, "SPRING_CLOUD");
|
||||
if (secure) {
|
||||
@@ -447,6 +458,22 @@ public class NacosDiscoveryProperties {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public boolean isInstanceEnabled() {
|
||||
return instanceEnabled;
|
||||
}
|
||||
|
||||
public void setInstanceEnabled(boolean instanceEnabled) {
|
||||
this.instanceEnabled = instanceEnabled;
|
||||
}
|
||||
|
||||
public boolean isEphemeral() {
|
||||
return ephemeral;
|
||||
}
|
||||
|
||||
public void setEphemeral(boolean ephemeral) {
|
||||
this.ephemeral = ephemeral;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "NacosDiscoveryProperties{" + "serverAddr='" + serverAddr + '\''
|
||||
|
||||
+4
-1
@@ -92,7 +92,10 @@ public class NacosServiceDiscovery {
|
||||
metadata.put("nacos.weight", instance.getWeight() + "");
|
||||
metadata.put("nacos.healthy", instance.isHealthy() + "");
|
||||
metadata.put("nacos.cluster", instance.getClusterName() + "");
|
||||
metadata.putAll(instance.getMetadata());
|
||||
if (instance.getMetadata() != null) {
|
||||
metadata.putAll(instance.getMetadata());
|
||||
}
|
||||
metadata.put("nacos.ephemeral",String.valueOf(instance.isEphemeral()));
|
||||
nacosServiceInstance.setMetadata(metadata);
|
||||
|
||||
if (metadata.containsKey("secure")) {
|
||||
|
||||
+9
-5
@@ -33,6 +33,7 @@ import static org.springframework.util.ReflectionUtils.rethrowRuntimeException;
|
||||
/**
|
||||
* @author xiaojing
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
* @author <a href="mailto:78552423@qq.com">eshun</a>
|
||||
*/
|
||||
public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
|
||||
@@ -40,11 +41,8 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
|
||||
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||
|
||||
private final NamingService namingService;
|
||||
|
||||
public NacosServiceRegistry(NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||
this.namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,6 +53,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
return;
|
||||
}
|
||||
|
||||
NamingService namingService = namingService();
|
||||
String serviceId = registration.getServiceId();
|
||||
String group = nacosDiscoveryProperties.getGroup();
|
||||
|
||||
@@ -84,7 +83,7 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
return;
|
||||
}
|
||||
|
||||
NamingService namingService = nacosDiscoveryProperties.namingServiceInstance();
|
||||
NamingService namingService = namingService();
|
||||
String serviceId = registration.getServiceId();
|
||||
String group = nacosDiscoveryProperties.getGroup();
|
||||
|
||||
@@ -160,9 +159,14 @@ public class NacosServiceRegistry implements ServiceRegistry<Registration> {
|
||||
instance.setPort(registration.getPort());
|
||||
instance.setWeight(nacosDiscoveryProperties.getWeight());
|
||||
instance.setClusterName(nacosDiscoveryProperties.getClusterName());
|
||||
instance.setEnabled(nacosDiscoveryProperties.isInstanceEnabled());
|
||||
instance.setMetadata(registration.getMetadata());
|
||||
|
||||
instance.setEphemeral(nacosDiscoveryProperties.isEphemeral());
|
||||
return instance;
|
||||
}
|
||||
|
||||
private NamingService namingService() {
|
||||
return nacosDiscoveryProperties.namingServiceInstance();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-1
@@ -51,12 +51,13 @@ public class NacosRule extends AbstractLoadBalancerRule {
|
||||
public Server choose(Object key) {
|
||||
try {
|
||||
String clusterName = this.nacosDiscoveryProperties.getClusterName();
|
||||
String group = this.nacosDiscoveryProperties.getGroup();
|
||||
DynamicServerListLoadBalancer loadBalancer = (DynamicServerListLoadBalancer) getLoadBalancer();
|
||||
String name = loadBalancer.getName();
|
||||
|
||||
NamingService namingService = nacosDiscoveryProperties
|
||||
.namingServiceInstance();
|
||||
List<Instance> instances = namingService.selectInstances(name, true);
|
||||
List<Instance> instances = namingService.selectInstances(name, group, true);
|
||||
if (CollectionUtils.isEmpty(instances)) {
|
||||
LOGGER.warn("no instance in service {}", name);
|
||||
return null;
|
||||
|
||||
+12
@@ -23,6 +23,18 @@
|
||||
"defaultValue": true,
|
||||
"description": "enable nacos discovery or not."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.instance-enabled",
|
||||
"type": "java.lang.Boolean",
|
||||
"defaultValue": true,
|
||||
"description": "If instance is enabled to accept request. The default value is true."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.ephemeral",
|
||||
"type": "java.lang.Boolean",
|
||||
"defaultValue": true,
|
||||
"description": "If instance is ephemeral.The default value is true."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.nacos.discovery.namingLoadCacheAtStart",
|
||||
"type": "java.lang.Boolean",
|
||||
|
||||
@@ -153,6 +153,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
+14
@@ -102,6 +102,20 @@ public class SentinelProperties {
|
||||
*/
|
||||
private Boolean httpMethodSpecify = false;
|
||||
|
||||
/**
|
||||
* Specify whether unify web context(i.e. use the default context name), and is true
|
||||
* by default.
|
||||
*/
|
||||
private Boolean webContextUnify = true;
|
||||
|
||||
public Boolean getWebContextUnify() {
|
||||
return webContextUnify;
|
||||
}
|
||||
|
||||
public void setWebContextUnify(Boolean webContextUnify) {
|
||||
this.webContextUnify = webContextUnify;
|
||||
}
|
||||
|
||||
public boolean isEager() {
|
||||
return eager;
|
||||
}
|
||||
|
||||
+1
@@ -96,6 +96,7 @@ public class SentinelWebAutoConfiguration implements WebMvcConfigurer {
|
||||
public SentinelWebMvcConfig sentinelWebMvcConfig() {
|
||||
SentinelWebMvcConfig sentinelWebMvcConfig = new SentinelWebMvcConfig();
|
||||
sentinelWebMvcConfig.setHttpMethodSpecify(properties.getHttpMethodSpecify());
|
||||
sentinelWebMvcConfig.setWebContextUnify(properties.getWebContextUnify());
|
||||
|
||||
if (blockExceptionHandlerOptional.isPresent()) {
|
||||
blockExceptionHandlerOptional
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ public class SentinelEndpoint {
|
||||
result.put("metricsFileSize", SentinelConfig.singleMetricFileSize());
|
||||
result.put("metricsFileCharset", SentinelConfig.charset());
|
||||
result.put("totalMetricsFileCount", SentinelConfig.totalMetricFileCount());
|
||||
result.put("consoleServer", TransportConfig.getConsoleServer());
|
||||
result.put("consoleServer", TransportConfig.getConsoleServerList());
|
||||
result.put("clientIp", TransportConfig.getHeartbeatClientIp());
|
||||
result.put("heartbeatIntervalMs", TransportConfig.getHeartbeatIntervalMs());
|
||||
result.put("clientPort", TransportConfig.getPort());
|
||||
|
||||
+10
-5
@@ -17,6 +17,7 @@
|
||||
package com.alibaba.cloud.sentinel.endpoint;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.cloud.sentinel.SentinelProperties;
|
||||
@@ -24,13 +25,14 @@ import com.alibaba.csp.sentinel.datasource.AbstractDataSource;
|
||||
import com.alibaba.csp.sentinel.heartbeat.HeartbeatSenderProvider;
|
||||
import com.alibaba.csp.sentinel.transport.HeartbeatSender;
|
||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||
import com.alibaba.csp.sentinel.util.function.Tuple2;
|
||||
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Health;
|
||||
import org.springframework.boot.actuate.health.HealthIndicator;
|
||||
import org.springframework.boot.actuate.health.Status;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* A {@link HealthIndicator} for Sentinel, which checks the status of Sentinel Dashboard
|
||||
@@ -82,8 +84,9 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
||||
|
||||
// Check health of Dashboard
|
||||
boolean dashboardUp = true;
|
||||
String consoleServer = TransportConfig.getConsoleServer();
|
||||
if (StringUtils.isEmpty(consoleServer)) {
|
||||
List<Tuple2<String, Integer>> consoleServerList = TransportConfig
|
||||
.getConsoleServerList();
|
||||
if (CollectionUtils.isEmpty(consoleServerList)) {
|
||||
// If Dashboard isn't configured, it's OK and mark the status of Dashboard
|
||||
// with UNKNOWN.
|
||||
detailMap.put("dashboard",
|
||||
@@ -101,8 +104,10 @@ public class SentinelHealthIndicator extends AbstractHealthIndicator {
|
||||
else {
|
||||
// If failed to send heartbeat message, means that the Dashboard is DOWN
|
||||
dashboardUp = false;
|
||||
detailMap.put("dashboard", new Status(Status.DOWN.getCode(),
|
||||
consoleServer + " can't be connected"));
|
||||
detailMap.put("dashboard",
|
||||
new Status(Status.DOWN.getCode(), String.format(
|
||||
"the dashboard servers [%s] one of them can't be connected",
|
||||
consoleServerList)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -18,6 +18,12 @@
|
||||
"defaultValue": false,
|
||||
"description": "earlier initialize heart-beat when the spring container starts when the transport dependency is on classpath, the configuration is effective."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.sentinel.web-context-unify",
|
||||
"type": "java.lang.Boolean",
|
||||
"defaultValue": true,
|
||||
"description": "Specify whether unify web context(i.e. use the default context name), and is true by default."
|
||||
},
|
||||
{
|
||||
"name": "spring.cloud.sentinel.transport.port",
|
||||
"type": "java.lang.String",
|
||||
|
||||
+9
-4
@@ -33,6 +33,7 @@ import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRuleManager;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRule;
|
||||
import com.alibaba.csp.sentinel.slots.block.flow.FlowRuleManager;
|
||||
import com.alibaba.csp.sentinel.transport.config.TransportConfig;
|
||||
import com.alibaba.csp.sentinel.util.function.Tuple2;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -73,7 +74,7 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
|
||||
"spring.cloud.sentinel.flow.coldFactor=3",
|
||||
"spring.cloud.sentinel.eager=true",
|
||||
"spring.cloud.sentinel.log.switchPid=true",
|
||||
"spring.cloud.sentinel.transport.dashboard=http://localhost:8080",
|
||||
"spring.cloud.sentinel.transport.dashboard=http://localhost:8080,http://localhost:8081",
|
||||
"spring.cloud.sentinel.transport.port=9999",
|
||||
"spring.cloud.sentinel.transport.clientIp=1.1.1.1",
|
||||
"spring.cloud.sentinel.transport.heartbeatIntervalMs=20000" },
|
||||
@@ -142,7 +143,9 @@ public class SentinelAutoConfigurationTests {
|
||||
Map<String, Object> map = sentinelEndpoint.invoke();
|
||||
|
||||
assertThat(map.get("logUsePid")).isEqualTo(Boolean.TRUE);
|
||||
assertThat(map.get("consoleServer")).isEqualTo("http://localhost:8080");
|
||||
assertThat(map.get("consoleServer").toString()).isEqualTo(
|
||||
Arrays.asList(Tuple2.of("localhost", 8080), Tuple2.of("localhost", 8081))
|
||||
.toString());
|
||||
assertThat(map.get("clientPort")).isEqualTo("9999");
|
||||
assertThat(map.get("heartbeatIntervalMs")).isEqualTo(20000L);
|
||||
assertThat(map.get("clientIp")).isEqualTo("1.1.1.1");
|
||||
@@ -174,7 +177,7 @@ public class SentinelAutoConfigurationTests {
|
||||
private void checkSentinelTransport() {
|
||||
assertThat(sentinelProperties.getTransport().getPort()).isEqualTo("9999");
|
||||
assertThat(sentinelProperties.getTransport().getDashboard())
|
||||
.isEqualTo("http://localhost:8080");
|
||||
.isEqualTo("http://localhost:8080,http://localhost:8081");
|
||||
assertThat(sentinelProperties.getTransport().getClientIp()).isEqualTo("1.1.1.1");
|
||||
assertThat(sentinelProperties.getTransport().getHeartbeatIntervalMs())
|
||||
.isEqualTo("20000");
|
||||
@@ -191,7 +194,9 @@ public class SentinelAutoConfigurationTests {
|
||||
@Test
|
||||
public void testSentinelSystemProperties() {
|
||||
assertThat(LogBase.isLogNameUsePid()).isEqualTo(true);
|
||||
assertThat(TransportConfig.getConsoleServer()).isEqualTo("http://localhost:8080");
|
||||
assertThat(TransportConfig.getConsoleServerList().toString()).isEqualTo(
|
||||
Arrays.asList(Tuple2.of("localhost", 8080), Tuple2.of("localhost", 8081))
|
||||
.toString());
|
||||
assertThat(TransportConfig.getPort()).isEqualTo("9999");
|
||||
assertThat(TransportConfig.getHeartbeatIntervalMs().longValue())
|
||||
.isEqualTo(20000L);
|
||||
|
||||
-2
@@ -18,7 +18,6 @@ package com.alibaba.cloud.sidecar;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
@@ -28,7 +27,6 @@ import org.springframework.web.client.RestTemplate;
|
||||
* @author www.itmuch.com
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableConfigurationProperties(SidecarProperties.class)
|
||||
public class SidecarAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
|
||||
+17
-5
@@ -17,12 +17,15 @@
|
||||
package com.alibaba.cloud.sidecar.nacos;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||
import com.alibaba.cloud.nacos.discovery.NacosDiscoveryAutoConfiguration;
|
||||
import com.alibaba.cloud.sidecar.SidecarAutoConfiguration;
|
||||
import com.alibaba.cloud.sidecar.SidecarDiscoveryClient;
|
||||
import com.alibaba.cloud.sidecar.SidecarProperties;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -30,15 +33,24 @@ import org.springframework.context.annotation.Configuration;
|
||||
* @author www.itmuch.com
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@AutoConfigureBefore(SidecarAutoConfiguration.class)
|
||||
@ConditionalOnBean(NacosDiscoveryProperties.class)
|
||||
@AutoConfigureBefore({ NacosDiscoveryAutoConfiguration.class,
|
||||
SidecarAutoConfiguration.class })
|
||||
@ConditionalOnClass(NacosDiscoveryProperties.class)
|
||||
@EnableConfigurationProperties(SidecarProperties.class)
|
||||
public class SidecarNacosAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties(
|
||||
SidecarProperties sidecarProperties) {
|
||||
return new SidecarNacosDiscoveryProperties(sidecarProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SidecarDiscoveryClient sidecarDiscoveryClient(
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
return new SidecarNacosDiscoveryClient(nacosDiscoveryProperties);
|
||||
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
||||
return new SidecarNacosDiscoveryClient(sidecarNacosDiscoveryProperties);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+9
-8
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.alibaba.cloud.sidecar.nacos;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||
import com.alibaba.cloud.sidecar.SidecarDiscoveryClient;
|
||||
import com.alibaba.nacos.api.exception.NacosException;
|
||||
import org.slf4j.Logger;
|
||||
@@ -30,18 +29,19 @@ public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient {
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(SidecarNacosDiscoveryClient.class);
|
||||
|
||||
private final NacosDiscoveryProperties nacosDiscoveryProperties;
|
||||
private final SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties;
|
||||
|
||||
public SidecarNacosDiscoveryClient(
|
||||
NacosDiscoveryProperties nacosDiscoveryProperties) {
|
||||
this.nacosDiscoveryProperties = nacosDiscoveryProperties;
|
||||
SidecarNacosDiscoveryProperties sidecarNacosDiscoveryProperties) {
|
||||
this.sidecarNacosDiscoveryProperties = sidecarNacosDiscoveryProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerInstance(String applicationName, String ip, Integer port) {
|
||||
try {
|
||||
this.nacosDiscoveryProperties.namingServiceInstance().registerInstance(
|
||||
applicationName, nacosDiscoveryProperties.getGroup(), ip, port);
|
||||
this.sidecarNacosDiscoveryProperties.namingServiceInstance().registerInstance(
|
||||
applicationName, sidecarNacosDiscoveryProperties.getGroup(), ip,
|
||||
port);
|
||||
}
|
||||
catch (NacosException e) {
|
||||
log.warn("nacos exception happens", e);
|
||||
@@ -51,8 +51,9 @@ public class SidecarNacosDiscoveryClient implements SidecarDiscoveryClient {
|
||||
@Override
|
||||
public void deregisterInstance(String applicationName, String ip, Integer port) {
|
||||
try {
|
||||
this.nacosDiscoveryProperties.namingServiceInstance().deregisterInstance(
|
||||
applicationName, nacosDiscoveryProperties.getGroup(), ip, port);
|
||||
this.sidecarNacosDiscoveryProperties.namingServiceInstance()
|
||||
.deregisterInstance(applicationName,
|
||||
sidecarNacosDiscoveryProperties.getGroup(), ip, port);
|
||||
}
|
||||
catch (NacosException e) {
|
||||
log.warn("nacos exception happens", e);
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* 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.sidecar.nacos;
|
||||
|
||||
import java.net.SocketException;
|
||||
|
||||
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
|
||||
import com.alibaba.cloud.sidecar.SidecarProperties;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author yuhuangbin
|
||||
*/
|
||||
public class SidecarNacosDiscoveryProperties extends NacosDiscoveryProperties {
|
||||
|
||||
SidecarProperties sidecarProperties;
|
||||
|
||||
public SidecarNacosDiscoveryProperties(SidecarProperties sidecarProperties) {
|
||||
this.sidecarProperties = sidecarProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws SocketException {
|
||||
super.init();
|
||||
|
||||
String ip = sidecarProperties.getIp();
|
||||
if (!StringUtils.isEmpty(ip)) {
|
||||
this.setIp(ip);
|
||||
}
|
||||
|
||||
Integer port = sidecarProperties.getPort();
|
||||
this.setPort(port);
|
||||
}
|
||||
|
||||
}
|
||||
+22
-12
@@ -76,12 +76,17 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
||||
|
||||
@Around("execution(* org.springframework.cloud.client.serviceregistry.Registration.getPort())")
|
||||
public Object getPort(ProceedingJoinPoint pjp) throws Throwable {
|
||||
/**
|
||||
* move setServerPort from onApplicationStarted() to here for this issue :
|
||||
* https://github.com/alibaba/spring-cloud-alibaba/issues/1383
|
||||
* @author <a href="mailto:chenxilzx1@gmail.com">theonefx</a>
|
||||
*/
|
||||
setServerPort();
|
||||
return serverPort != null ? serverPort : pjp.proceed();
|
||||
}
|
||||
|
||||
@EventListener(ApplicationStartedEvent.class)
|
||||
public void onApplicationStarted() {
|
||||
setServerPort();
|
||||
register();
|
||||
}
|
||||
|
||||
@@ -99,18 +104,22 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
||||
*/
|
||||
private void setServerPort() {
|
||||
if (serverPort == null) {
|
||||
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
||||
urls.stream()
|
||||
.filter(url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
||||
.findFirst().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
|
||||
// If REST protocol is not present, use any applied port.
|
||||
synchronized (DubboServiceRegistrationNonWebApplicationAutoConfiguration.class) {
|
||||
if (serverPort == null) {
|
||||
urls.stream().findAny().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
for (List<URL> urls : repository.getAllExportedUrls().values()) {
|
||||
urls.stream().filter(
|
||||
url -> REST_PROTOCOL.equalsIgnoreCase(url.getProtocol()))
|
||||
.findFirst().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
|
||||
// If REST protocol is not present, use any applied port.
|
||||
if (serverPort == null) {
|
||||
urls.stream().findAny().ifPresent(url -> {
|
||||
serverPort = url.getPort();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,6 +135,7 @@ public class DubboServiceRegistrationNonWebApplicationAutoConfiguration {
|
||||
@EventListener(ServiceInstancePreRegisteredEvent.class)
|
||||
public void onServiceInstancePreRegistered(
|
||||
ServiceInstancePreRegisteredEvent event) {
|
||||
setServerPort();
|
||||
registration.setPort(serverPort);
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -65,7 +65,6 @@ public class DubboProtocolConfigSupplier implements Supplier<ProtocolConfig> {
|
||||
if (protocolConfig == null) {
|
||||
protocolConfig = new ProtocolConfig();
|
||||
protocolConfig.setName(DEFAULT_PROTOCOL);
|
||||
protocolConfig.setPort(-1);
|
||||
}
|
||||
|
||||
return protocolConfig;
|
||||
|
||||
+3
-7
@@ -23,6 +23,7 @@ import com.alibaba.cloud.dubbo.util.JSONUtils;
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.registry.Registry;
|
||||
import org.apache.dubbo.registry.RegistryFactory;
|
||||
import org.apache.dubbo.registry.support.AbstractRegistryFactory;
|
||||
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -37,7 +38,7 @@ import static java.lang.System.getProperty;
|
||||
* @see RegistryFactory
|
||||
* @see SpringCloudRegistry
|
||||
*/
|
||||
public class SpringCloudRegistryFactory implements RegistryFactory {
|
||||
public class SpringCloudRegistryFactory extends AbstractRegistryFactory {
|
||||
|
||||
/**
|
||||
* Spring Cloud Protocol.
|
||||
@@ -65,8 +66,6 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
|
||||
|
||||
private DubboGenericServiceFactory dubboGenericServiceFactory;
|
||||
|
||||
private volatile boolean initialized = false;
|
||||
|
||||
public SpringCloudRegistryFactory() {
|
||||
}
|
||||
|
||||
@@ -76,9 +75,6 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
if (initialized || applicationContext == null) {
|
||||
return;
|
||||
}
|
||||
this.discoveryClient = applicationContext.getBean(DiscoveryClient.class);
|
||||
this.dubboServiceMetadataRepository = applicationContext
|
||||
.getBean(DubboServiceMetadataRepository.class);
|
||||
@@ -90,7 +86,7 @@ public class SpringCloudRegistryFactory implements RegistryFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Registry getRegistry(URL url) {
|
||||
public Registry createRegistry(URL url) {
|
||||
init();
|
||||
return new SpringCloudRegistry(url, discoveryClient,
|
||||
dubboServiceMetadataRepository, dubboMetadataConfigServiceProxy,
|
||||
|
||||
+1
-1
@@ -169,7 +169,7 @@ public class RocketMQMessageChannelBinder extends
|
||||
rocketMQTemplate, destination.getName(), producerGroup,
|
||||
producerProperties.getExtension().getTransactional(),
|
||||
instrumentationManager, producerProperties,
|
||||
((AbstractMessageChannel) channel).getChannelInterceptors().stream()
|
||||
((AbstractMessageChannel) channel).getInterceptors().stream()
|
||||
.filter(channelInterceptor -> channelInterceptor instanceof MessageConverterConfigurer.PartitioningInterceptor)
|
||||
.map(channelInterceptor -> ((MessageConverterConfigurer.PartitioningInterceptor) channelInterceptor))
|
||||
.findFirst().orElse(null));
|
||||
|
||||
Reference in New Issue
Block a user