change default dynamic config refresh type to reflect (#575)

pull/580/head
lepdou 2 years ago committed by GitHub
parent 62fecd49ba
commit 9dc3d054ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -35,3 +35,4 @@
- [Optimize: optimize report call result for restTemplate.](https://github.com/Tencent/spring-cloud-tencent/pull/565)
- [feat:add spring-cloud-starter-tencent-all and quickstart examples.](https://github.com/Tencent/spring-cloud-tencent/pull/569)
- [refactor:optimize project and code.](https://github.com/Tencent/spring-cloud-tencent/pull/571)
- - [Optimize:change default dynamic config refresh type to reflect.](https://github.com/Tencent/spring-cloud-tencent/pull/575)

@ -37,16 +37,17 @@ public class ReflectRefreshTypeCondition extends SpringBootCondition {
*/
public static final String POLARIS_CONFIG_REFRESH_TYPE = "spring.cloud.polaris.config.refresh-type";
private static final RefreshType DEFAULT_REFRESH_TYPE = RefreshType.REFRESH_CONTEXT;
private static final RefreshType DEFAULT_REFRESH_TYPE = RefreshType.REFLECT;
@Override
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) {
RefreshType refreshType = context.getEnvironment()
.getProperty(POLARIS_CONFIG_REFRESH_TYPE, RefreshType.class, DEFAULT_REFRESH_TYPE);
if (refreshType == DEFAULT_REFRESH_TYPE) {
return ConditionOutcome.noMatch("no matched");
}
if (refreshType == RefreshType.REFLECT) {
return ConditionOutcome.match("matched");
}
return ConditionOutcome.noMatch("no matched");
}
}

@ -63,7 +63,7 @@ public class PolarisConfigProperties {
/**
* Attribute refresh type.
*/
private RefreshType refreshType = RefreshType.REFRESH_CONTEXT;
private RefreshType refreshType = RefreshType.REFLECT;
/**
* List of injected configuration files.

@ -57,7 +57,7 @@
{
"name": "spring.cloud.polaris.config.refresh-type",
"type": "com.tencent.cloud.polaris.config.enums.RefreshType",
"defaultValue": "refresh_context",
"defaultValue": "reflect",
"description": "Attribute refresh type when config updated. refresh_context or reflect."
},
{

@ -100,6 +100,7 @@ public class ConditionalOnReflectRefreshTypeTest {
.withPropertyValues("spring.application.name=" + "conditionalOnConfigReflectEnabledTest")
.withPropertyValues("server.port=" + 8080)
.withPropertyValues("spring.cloud.polaris.address=grpc://127.0.0.1:10081")
.withPropertyValues("spring.cloud.polaris.config.refresh-type=" + RefreshType.REFRESH_CONTEXT)
.withPropertyValues("spring.cloud.polaris.config.enabled=true");
contextRunner.run(context -> {
assertThat(context).hasSingleBean(PolarisConfigProperties.class);

@ -0,0 +1,65 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.tencent.cloud.quickstart.callee;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Example for ConfigurationProperties.
* @author lepdou 2022-09-08
*/
@Component
@ConfigurationProperties("datasource")
public class DataSourceProperties {
private String jdbcUrl;
private String username;
private String password;
public String getJdbcUrl() {
return jdbcUrl;
}
public void setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
}
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;
}
@Override
public String toString() {
return "jdbcUrl='" + jdbcUrl + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'';
}
}

@ -20,6 +20,7 @@ package com.tencent.cloud.quickstart.callee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -43,6 +44,9 @@ public class QuickstartCalleeController {
@Value("${appName:Callee}")
private String appName;
@Autowired
private DataSourceProperties dataSourceProperties;
/**
* Get sum of two value.
* @param value1 value 1
@ -61,8 +65,8 @@ public class QuickstartCalleeController {
*/
@GetMapping("/info")
public String info() {
LOG.info("Quickstart [{}] Service [{}] is called.", appName, port);
return String.format("Quickstart [%s] Service [%s] is called.", appName, port);
LOG.info("Quickstart [{}] Service [{}] is called. datasource = {}", appName, port, dataSourceProperties);
return String.format("Quickstart [%s] Service [%s] is called. datasource = [%s]", appName, port, dataSourceProperties);
}
/**

@ -17,7 +17,6 @@ spring:
groups:
- name: ${spring.application.name}
files: [ "config/callee.properties" ]
refresh-type: reflect
ratelimit:
enabled: true
maxQueuingTime: 500

@ -0,0 +1,65 @@
/*
* Tencent is pleased to support the open source community by making Spring Cloud Tencent available.
*
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.tencent.cloud.quickstart.callee;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* Example for ConfigurationProperties.
* @author lepdou 2022-09-08
*/
@Component
@ConfigurationProperties("datasource")
public class DataSourceProperties {
private String jdbcUrl;
private String username;
private String password;
public String getJdbcUrl() {
return jdbcUrl;
}
public void setJdbcUrl(String jdbcUrl) {
this.jdbcUrl = jdbcUrl;
}
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;
}
@Override
public String toString() {
return "jdbcUrl='" + jdbcUrl + '\'' +
", username='" + username + '\'' +
", password='" + password + '\'';
}
}

@ -20,6 +20,7 @@ package com.tencent.cloud.quickstart.callee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
@ -45,6 +46,9 @@ public class QuickstartCalleeController {
@Value("${appName:Callee}")
private String appName;
@Autowired
private DataSourceProperties dataSourceProperties;
/**
* Get sum of two value.
* @param value1 value 1
@ -63,8 +67,8 @@ public class QuickstartCalleeController {
*/
@GetMapping("/info")
public String info() {
LOG.info("Quickstart [{}] Service [{}] is called.", appName, port);
return String.format("Quickstart [%s] Service [%s] is called.", appName, port);
LOG.info("Quickstart [{}] Service [{}] is called. datasource = {}", appName, port, dataSourceProperties);
return String.format("Quickstart [%s] Service [%s] is called. datasource = [%s]", appName, port, dataSourceProperties);
}
/**

@ -17,7 +17,6 @@ spring:
groups:
- name: ${spring.application.name}
files: [ "config/callee.properties" ]
refresh-type: reflect
ratelimit:
enabled: true
maxQueuingTime: 500

@ -34,6 +34,6 @@ public class QuickstartCalleeServiceFallback implements QuickstartCalleeService
@Override
public String circuitBreak() {
return "CircuitBreak is triggered.";
return "An exception occurred in the service call and fallback";
}
}

@ -1,14 +0,0 @@
consumer:
circuitBreaker:
checkPeriod: 100ms
chain:
- errorCount
- errorRate
plugin:
errorCount:
continuousErrorThreshold: 1
metricNumBuckets: 1
errorRate:
errorRateThreshold: 100
metricStatTimeWindow: 1s
requestVolumeThreshold: 1
Loading…
Cancel
Save