diff --git a/CHANGELOG.md b/CHANGELOG.md
index 258d409eb..eb4a85ddc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,4 +32,5 @@
- [Report the labels in request when report the result of invocation by Feign](https://github.com/Tencent/spring-cloud-tencent/pull/555)
- [fix:fix heartbeat interval different configuration from polaris-java SDK.](https://github.com/Tencent/spring-cloud-tencent/pull/558)
- [Optimize: optimize report call result for restTemplate.](https://github.com/Tencent/spring-cloud-tencent/pull/564)
+- [feat:add spring-cloud-starter-tencent-all and quickstart examples.](https://github.com/Tencent/spring-cloud-tencent/pull/568)
- [refactor:optimize project and code.](https://github.com/Tencent/spring-cloud-tencent/pull/570)
diff --git a/pom.xml b/pom.xml
index 994cbcd02..ac0626424 100644
--- a/pom.xml
+++ b/pom.xml
@@ -50,6 +50,7 @@
spring-cloud-starter-tencent-polaris-router
spring-cloud-tencent-plugin-starters
spring-cloud-tencent-dependencies
+ spring-cloud-starter-tencent-all
spring-cloud-tencent-examples
spring-cloud-tencent-coverage
diff --git a/spring-cloud-starter-tencent-all/pom.xml b/spring-cloud-starter-tencent-all/pom.xml
new file mode 100644
index 000000000..1aaa8bbc7
--- /dev/null
+++ b/spring-cloud-starter-tencent-all/pom.xml
@@ -0,0 +1,66 @@
+
+
+
+ spring-cloud-tencent
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ spring-cloud-starter-tencent-all
+ Spring Cloud Starter Tencent ALL In One
+ pom
+
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-discovery
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-config
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-ratelimit
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-circuitbreaker
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-polaris-router
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-metadata-transfer
+
+
+
+ com.tencent.cloud
+ spring-cloud-tencent-pushgateway-plugin
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
diff --git a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java
index 0edd584fb..ca966159f 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java
+++ b/spring-cloud-starter-tencent-polaris-config/src/main/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessor.java
@@ -149,7 +149,7 @@ public class SpringValueProcessor extends PolarisProcessor implements BeanFactor
return;
}
springValueRegistry.register(beanFactory, key, springValue);
- LOGGER.info("Monitoring {}", springValue);
+ LOGGER.debug("Monitoring {}", springValue);
}
}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/condition/ConditionalOnReflectRefreshTypeTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/condition/ConditionalOnReflectRefreshTypeTest.java
index 80b8dbbcc..182883ab2 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/condition/ConditionalOnReflectRefreshTypeTest.java
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/condition/ConditionalOnReflectRefreshTypeTest.java
@@ -60,7 +60,7 @@ public class ConditionalOnReflectRefreshTypeTest {
serverSocket.accept();
}
catch (IOException e) {
- //ignore
+ e.printStackTrace();
}
}).start();
}
diff --git a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java
index 6ad500ae3..99f1b9b14 100644
--- a/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java
+++ b/spring-cloud-starter-tencent-polaris-config/src/test/java/com/tencent/cloud/polaris/config/spring/annotation/SpringValueProcessorTest.java
@@ -62,7 +62,7 @@ public class SpringValueProcessorTest {
serverSocket.accept();
}
catch (IOException e) {
- //ignore
+ e.printStackTrace();
}
}).start();
}
@@ -156,11 +156,10 @@ public class SpringValueProcessorTest {
@Component
private static class ValueTest {
+ private static String name;
@Value("${timeout:1000}")
private int timeout;
- private static String name;
-
public int getTimeout() {
return timeout;
}
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java
index 8a1162ee6..193235385 100644
--- a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckReactiveFilter.java
@@ -98,7 +98,7 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
String localService = MetadataContext.LOCAL_SERVICE;
Map labels = getRequestLabels(exchange, localNamespace, localService);
-
+ long waitMs = -1;
try {
String path = exchange.getRequest().getURI().getPath();
QuotaResponse quotaResponse = QuotaCheckUtils.getQuota(limitAPI,
@@ -115,7 +115,7 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
// Unirate
if (quotaResponse.getCode() == QuotaResultCode.QuotaResultOk && quotaResponse.getWaitMs() > 0) {
LOGGER.debug("The request of [{}] will waiting for {}ms.", path, quotaResponse.getWaitMs());
- return Mono.delay(Duration.ofMillis(quotaResponse.getWaitMs())).flatMap(e -> chain.filter(exchange));
+ waitMs = quotaResponse.getWaitMs();
}
}
catch (Throwable t) {
@@ -124,7 +124,12 @@ public class QuotaCheckReactiveFilter implements WebFilter, Ordered {
LOGGER.error("fail to invoke getQuota, service is " + localService, t);
}
- return chain.filter(exchange);
+ if (waitMs > 0) {
+ return Mono.delay(Duration.ofMillis(waitMs)).flatMap(e -> chain.filter(exchange));
+ }
+ else {
+ return chain.filter(exchange);
+ }
}
private Map getRequestLabels(ServerWebExchange exchange, String localNamespace, String localService) {
diff --git a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java
index c75ed1e05..f10a36c57 100644
--- a/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java
+++ b/spring-cloud-starter-tencent-polaris-ratelimit/src/main/java/com/tencent/cloud/polaris/ratelimit/filter/QuotaCheckServletFilter.java
@@ -114,14 +114,14 @@ public class QuotaCheckServletFilter extends OncePerRequestFilter {
Thread.sleep(quotaResponse.getWaitMs());
}
- filterChain.doFilter(request, response);
}
catch (Throwable t) {
// An exception occurs in the rate limiting API call,
// which should not affect the call of the business process.
LOG.error("fail to invoke getQuota, service is " + localService, t);
- filterChain.doFilter(request, response);
}
+
+ filterChain.doFilter(request, response);
}
private Map getRequestLabels(HttpServletRequest request, String localNamespace, String localService) {
diff --git a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java
index 2413e3778..2e236eaba 100644
--- a/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java
+++ b/spring-cloud-tencent-commons/src/main/java/com/tencent/cloud/common/metadata/StaticMetadataManager.java
@@ -70,8 +70,8 @@ public class StaticMetadataManager {
private Map mergedStaticMetadata;
private Map mergedStaticTransitiveMetadata;
private Map mergedStaticDisposableMetadata;
- private String zone;
private String region;
+ private String zone;
private String campus;
public StaticMetadataManager(MetadataLocalProperties metadataLocalProperties,
@@ -231,17 +231,6 @@ public class StaticMetadataManager {
private void parseLocationMetadata(MetadataLocalProperties metadataLocalProperties,
InstanceMetadataProvider instanceMetadataProvider) {
- // resolve zone info
- if (instanceMetadataProvider != null) {
- zone = instanceMetadataProvider.getZone();
- }
- if (StringUtils.isBlank(zone)) {
- zone = System.getenv(ENV_METADATA_ZONE);
- }
- if (StringUtils.isBlank(zone)) {
- zone = metadataLocalProperties.getContent().get(LOCATION_KEY_ZONE);
- }
-
// resolve region info
if (instanceMetadataProvider != null) {
region = instanceMetadataProvider.getRegion();
@@ -253,6 +242,17 @@ public class StaticMetadataManager {
region = metadataLocalProperties.getContent().get(LOCATION_KEY_REGION);
}
+ // resolve zone info
+ if (instanceMetadataProvider != null) {
+ zone = instanceMetadataProvider.getZone();
+ }
+ if (StringUtils.isBlank(zone)) {
+ zone = System.getenv(ENV_METADATA_ZONE);
+ }
+ if (StringUtils.isBlank(zone)) {
+ zone = metadataLocalProperties.getContent().get(LOCATION_KEY_ZONE);
+ }
+
// resolve campus info
if (instanceMetadataProvider != null) {
campus = instanceMetadataProvider.getCampus();
diff --git a/spring-cloud-tencent-dependencies/pom.xml b/spring-cloud-tencent-dependencies/pom.xml
index 8f2430147..8573a2cf7 100644
--- a/spring-cloud-tencent-dependencies/pom.xml
+++ b/spring-cloud-tencent-dependencies/pom.xml
@@ -73,7 +73,7 @@
1.7.0-2020.0.5-SNAPSHOT
- 1.7.3
+ 1.7.4-SNAPSHOT
1.2.11
4.5.1
1.12.10
@@ -81,7 +81,6 @@
3.16.1
1.69
31.0.1-jre
- 0.11.0
3.2.0
@@ -160,6 +159,13 @@
${revision}
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-all
+ pom
+ ${revision}
+
+
com.tencent.cloud
@@ -248,12 +254,6 @@
${byte-buddy.version}
-
- io.prometheus
- simpleclient_pushgateway
- ${prometheus.version}
-
-
org.mockito
mockito-inline
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml
index bc5a699ef..42dbeeb6e 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-callee-service/src/main/resources/bootstrap.yml
@@ -11,6 +11,9 @@ spring:
discovery:
enabled: true
register: true
+ rpc-enhancement:
+ reporter:
+ enabled: true
stat:
enabled: true
port: 28082
diff --git a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
index 5384f4ac2..eaf197281 100644
--- a/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-discovery-example/discovery-caller-service/src/main/resources/bootstrap.yml
@@ -22,6 +22,10 @@ spring:
stat:
enabled: true
port: 28081
+ tencent:
+ rpc-enhancement:
+ reporter:
+ enabled: true
# pushgateway:
# enabled: true
# address: 127.0.0.1:9091
diff --git a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml
index ebf385deb..06f431b8f 100644
--- a/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml
+++ b/spring-cloud-tencent-examples/polaris-ratelimit-example/ratelimit-callee-service/src/main/resources/bootstrap.yml
@@ -11,7 +11,7 @@ spring:
ratelimit:
enabled: true
rejectRequestTipsFilePath: reject-tips.html
- maxQueuingTime: 1000
+ maxQueuingTime: 500
management:
endpoints:
diff --git a/spring-cloud-tencent-examples/pom.xml b/spring-cloud-tencent-examples/pom.xml
index ada8e13e2..0d5ea1c21 100644
--- a/spring-cloud-tencent-examples/pom.xml
+++ b/spring-cloud-tencent-examples/pom.xml
@@ -25,6 +25,7 @@
metadata-transfer-example
polaris-router-grayrelease-example
polaris-router-featureenv-example
+ quickstart-example
diff --git a/spring-cloud-tencent-examples/quickstart-example/pom.xml b/spring-cloud-tencent-examples/quickstart-example/pom.xml
new file mode 100644
index 000000000..07bd50ffc
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/pom.xml
@@ -0,0 +1,23 @@
+
+
+
+ spring-cloud-tencent-examples
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ quickstart-example
+ pom
+ Spring Cloud Starter Tencent Quickstart Example
+
+
+ quickstart-gateway-service
+ quickstart-caller-service
+ quickstart-callee-service-a
+ quickstart-callee-service-b
+
+
\ No newline at end of file
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/pom.xml b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/pom.xml
new file mode 100644
index 000000000..b569ce913
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ quickstart-example
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ quickstart-callee-service-a
+ Quickstart Callee Service A
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-all
+ pom
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomConfigChangeListener.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomConfigChangeListener.java
new file mode 100644
index 000000000..cf2e92017
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomConfigChangeListener.java
@@ -0,0 +1,47 @@
+/*
+ * 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 java.util.Set;
+
+import com.tencent.cloud.polaris.config.annotation.PolarisConfigKVFileChangeListener;
+import com.tencent.cloud.polaris.config.listener.ConfigChangeEvent;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Custom Config Listener Example .
+ *
+ * @author Haotian Zhang
+ */
+@Component
+public final class CustomConfigChangeListener {
+
+ /**
+ * PolarisConfigKVFileChangeListener Example .
+ * @param event instance of {@link ConfigChangeEvent}
+ */
+ @PolarisConfigKVFileChangeListener(interestedKeyPrefixes = "appName")
+ public void onChange(ConfigChangeEvent event) {
+ Set changedKeys = event.changedKeys();
+
+ for (String changedKey : changedKeys) {
+ System.out.printf("%s = %s \n", changedKey, event.getChange(changedKey));
+ }
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java
new file mode 100644
index 000000000..bdd60f8ef
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import com.tencent.cloud.common.spi.InstanceMetadataProvider;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Custom metadata for instance.
+ *
+ * @author Haotian Zhang
+ */
+@Component
+public class CustomMetadata implements InstanceMetadataProvider {
+
+ @Override
+ public Map getMetadata() {
+ Map metadata = new HashMap<>();
+ metadata.put("k1", "v1");
+ return metadata;
+ }
+
+ @Override
+ public String getZone() {
+ return "shenzhen-zone-1";
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
new file mode 100644
index 000000000..02920c291
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
@@ -0,0 +1,78 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Quickstart callee controller.
+ *
+ * @author Haotian Zhang
+ */
+@RestController
+@RequestMapping("/quickstart/callee")
+public class QuickstartCalleeController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(QuickstartCalleeController.class);
+
+ @Value("${server.port:0}")
+ private int port;
+
+ @Value("${appName:Callee}")
+ private String appName;
+
+ /**
+ * Get sum of two value.
+ * @param value1 value 1
+ * @param value2 value 2
+ * @return sum
+ */
+ @GetMapping("/sum")
+ public int sum(@RequestParam int value1, @RequestParam int value2) {
+ LOG.info("Quickstart Callee Service is called and sum is {}.", value1 + value2);
+ return value1 + value2;
+ }
+
+ /**
+ * Get information of callee.
+ * @return information of callee
+ */
+ @GetMapping("/info")
+ public String info() {
+ LOG.info("Quickstart [{}] Service [{}] is called.", appName, port);
+ return String.format("Quickstart [%s] Service [%s] is called.", appName, port);
+ }
+
+ /**
+ * Check circuit break.
+ *
+ * @return circuit break info
+ */
+ @GetMapping("/circuitBreak")
+ public String circuitBreak() {
+ LOG.info("Quickstart Callee Service is called right.");
+ return "Quickstart Callee Service is called right.";
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceA.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceA.java
new file mode 100644
index 000000000..fb00d56ed
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceA.java
@@ -0,0 +1,34 @@
+/*
+ * 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.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * Quickstart callee application.
+ *
+ * @author Haotian Zhang
+ */
+@SpringBootApplication
+public class QuickstartCalleeServiceA {
+
+ public static void main(String[] args) {
+ SpringApplication.run(QuickstartCalleeServiceA.class, args);
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/bootstrap.yml
new file mode 100644
index 000000000..65ba0b54c
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/resources/bootstrap.yml
@@ -0,0 +1,27 @@
+server:
+ port: 48083
+spring:
+ application:
+ name: QuickstartCalleeService
+ cloud:
+ polaris:
+ address: grpc://183.47.111.80:8091
+ namespace: default
+ enabled: true
+ discovery:
+ enabled: true
+ register: true
+ config:
+ address: grpc://183.47.111.80:8093
+ auto-refresh: true
+ groups:
+ - name: ${spring.application.name}
+ files: [ "config/callee.properties" ]
+ refresh-type: reflect
+ ratelimit:
+ enabled: true
+ maxQueuingTime: 500
+ tencent:
+ metadata:
+ content:
+ region: huanan
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/pom.xml b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/pom.xml
new file mode 100644
index 000000000..c5f525b39
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ quickstart-example
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ quickstart-callee-service-b
+ Quickstart Callee Service B
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-all
+ pom
+
+
+
+ org.springframework.boot
+ spring-boot-starter-webflux
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomConfigChangeListener.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomConfigChangeListener.java
new file mode 100644
index 000000000..0bcfb554a
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomConfigChangeListener.java
@@ -0,0 +1,48 @@
+/*
+ * 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 java.util.Set;
+
+import com.tencent.cloud.polaris.config.annotation.PolarisConfigKVFileChangeListener;
+import com.tencent.cloud.polaris.config.listener.ConfigChangeEvent;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Custom Config Listener Example .
+ *
+ * @author Haotian Zhang
+ */
+@Component
+public final class CustomConfigChangeListener {
+
+ /**
+ * PolarisConfigKVFileChangeListener Example .
+ * @param event instance of {@link ConfigChangeEvent}
+ */
+ @PolarisConfigKVFileChangeListener(interestedKeyPrefixes = "appName")
+ public void onChange(ConfigChangeEvent event) {
+ Set changedKeys = event.changedKeys();
+
+ for (String changedKey : changedKeys) {
+ System.out.printf("%s = %s \n", changedKey, event.getChange(changedKey));
+ }
+ }
+
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java
new file mode 100644
index 000000000..8257f2cd5
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java
@@ -0,0 +1,46 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import com.tencent.cloud.common.spi.InstanceMetadataProvider;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Custom metadata for instance.
+ *
+ * @author Haotian Zhang
+ */
+@Component
+public class CustomMetadata implements InstanceMetadataProvider {
+
+ @Override
+ public Map getMetadata() {
+ Map metadata = new HashMap<>();
+ metadata.put("k1", "v2");
+ return metadata;
+ }
+
+ @Override
+ public String getZone() {
+ return "shenzhen-zone-2";
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
new file mode 100644
index 000000000..a690a23c2
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java
@@ -0,0 +1,81 @@
+/*
+ * 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * Quickstart callee controller.
+ *
+ * @author Haotian Zhang
+ */
+@RestController
+@RequestMapping("/quickstart/callee")
+public class QuickstartCalleeController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(QuickstartCalleeController.class);
+
+ @Value("${server.port:0}")
+ private int port;
+
+ @Value("${appName:Callee}")
+ private String appName;
+
+ /**
+ * Get sum of two value.
+ * @param value1 value 1
+ * @param value2 value 2
+ * @return sum
+ */
+ @GetMapping("/sum")
+ public int sum(@RequestParam int value1, @RequestParam int value2) {
+ LOG.info("Quickstart Callee Service is called and sum is {}.", value1 + value2);
+ return value1 + value2;
+ }
+
+ /**
+ * Get information of callee.
+ * @return information of callee
+ */
+ @GetMapping("/info")
+ public String info() {
+ LOG.info("Quickstart [{}] Service [{}] is called.", appName, port);
+ return String.format("Quickstart [%s] Service [%s] is called.", appName, port);
+ }
+
+ /**
+ * Check circuit break.
+ *
+ * @return circuit break info
+ */
+ @GetMapping("/circuitBreak")
+ @ResponseStatus(value = HttpStatus.BAD_GATEWAY, reason = "failed for call quickstart callee service")
+ public String circuitBreak() {
+ LOG.info("Quickstart Callee Service [{}] is called wrong.", port);
+ return String.format("Quickstart Callee Service [%s] is called wrong.", port);
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceB.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceB.java
new file mode 100644
index 000000000..c2740e40d
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceB.java
@@ -0,0 +1,34 @@
+/*
+ * 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.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * Quickstart callee application.
+ *
+ * @author Haotian Zhang
+ */
+@SpringBootApplication
+public class QuickstartCalleeServiceB {
+
+ public static void main(String[] args) {
+ SpringApplication.run(QuickstartCalleeServiceB.class, args);
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/resources/bootstrap.yml
new file mode 100644
index 000000000..f2e845e73
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/resources/bootstrap.yml
@@ -0,0 +1,27 @@
+server:
+ port: 48084
+spring:
+ application:
+ name: QuickstartCalleeService
+ cloud:
+ polaris:
+ address: grpc://183.47.111.80:8091
+ namespace: default
+ enabled: true
+ discovery:
+ enabled: true
+ register: true
+ config:
+ address: grpc://183.47.111.80:8093
+ auto-refresh: true
+ groups:
+ - name: ${spring.application.name}
+ files: [ "config/callee.properties" ]
+ refresh-type: reflect
+ ratelimit:
+ enabled: true
+ maxQueuingTime: 500
+ tencent:
+ metadata:
+ content:
+ region: huanan
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/pom.xml b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/pom.xml
new file mode 100644
index 000000000..d9f796cb0
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/pom.xml
@@ -0,0 +1,57 @@
+
+
+
+ quickstart-example
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ quickstart-caller-service
+ Quickstart Caller Service
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-all
+ pom
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java
new file mode 100644
index 000000000..16486dfc9
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java
@@ -0,0 +1,49 @@
+/*
+ * 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.caller;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+/**
+ * Quickstart callee feign client.
+ *
+ * @author Haotian Zhang
+ */
+@FeignClient(value = "QuickstartCalleeService", fallback = QuickstartCalleeServiceFallback.class)
+public interface QuickstartCalleeService {
+
+ /**
+ * Get sum of two value.
+ *
+ * @param value1 value 1
+ * @param value2 value 2
+ * @return sum
+ */
+ @GetMapping("/quickstart/callee/sum")
+ int sum(@RequestParam("value1") int value1, @RequestParam("value2") int value2);
+
+ /**
+ * Check circuit break.
+ *
+ * @return circuit break info
+ */
+ @GetMapping("/quickstart/callee/circuitBreak")
+ String circuitBreak();
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.java
new file mode 100644
index 000000000..4e7a00035
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.java
@@ -0,0 +1,39 @@
+/*
+ * 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.caller;
+
+import org.springframework.stereotype.Component;
+
+/**
+ * Quickstart callee feign client fallback.
+ *
+ * @author Haotian Zhang
+ */
+@Component
+public class QuickstartCalleeServiceFallback implements QuickstartCalleeService {
+
+ @Override
+ public int sum(int value1, int value2) {
+ return 0;
+ }
+
+ @Override
+ public String circuitBreak() {
+ return "CircuitBreak is triggered.";
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java
new file mode 100644
index 000000000..904a2a501
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java
@@ -0,0 +1,45 @@
+/*
+ * 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.caller;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.client.loadbalancer.LoadBalanced;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Quickstart caller application.
+ *
+ * @author Haotian Zhang
+ */
+@SpringBootApplication
+@EnableFeignClients
+public class QuickstartCallerApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(QuickstartCallerApplication.class, args);
+ }
+
+ @Bean
+ @LoadBalanced
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java
new file mode 100644
index 000000000..40b1233ab
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java
@@ -0,0 +1,170 @@
+/*
+ * 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.caller;
+
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Quickstart caller controller.
+ *
+ * @author Haotian Zhang
+ */
+@RestController
+@RequestMapping("/quickstart/caller")
+public class QuickstartCallerController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(QuickstartCallerController.class);
+ @Autowired
+ private RestTemplate restTemplate;
+ @Autowired
+ private QuickstartCalleeService quickstartCalleeService;
+
+ /**
+ * Get sum of two value.
+ * @param value1 value 1
+ * @param value2 value 2
+ * @return sum
+ */
+ @GetMapping("/feign")
+ public int feign(@RequestParam int value1, @RequestParam int value2) {
+ return quickstartCalleeService.sum(value1, value2);
+ }
+
+ /**
+ * Get information of callee.
+ * @return information of callee
+ */
+ @GetMapping("/rest")
+ public String rest() {
+ return restTemplate.getForObject("http://QuickstartCalleeService/quickstart/callee/info", String.class);
+ }
+
+ /**
+ * Get information of callee.
+ * @return information of callee
+ */
+ @GetMapping("/circuitBreak")
+ public String circuitBreak() {
+ return quickstartCalleeService.circuitBreak();
+ }
+
+ /**
+ * Get information 30 times per 1 second.
+ *
+ * @return result of 30 calls.
+ * @throws InterruptedException exception
+ */
+ @GetMapping("/ratelimit")
+ public String invokeInfo() throws InterruptedException {
+ StringBuffer builder = new StringBuffer();
+ CountDownLatch count = new CountDownLatch(30);
+ AtomicInteger index = new AtomicInteger(0);
+ for (int i = 0; i < 30; i++) {
+ new Thread(() -> {
+ try {
+ ResponseEntity entity = restTemplate.getForEntity(
+ "http://QuickstartCalleeService/quickstart/callee/info", String.class);
+ builder.append(entity.getBody() + "\n");
+ }
+ catch (RestClientException e) {
+ if (e instanceof HttpClientErrorException.TooManyRequests) {
+ builder.append("TooManyRequests " + index.incrementAndGet() + "\n");
+ }
+ else {
+ throw e;
+ }
+ }
+ count.countDown();
+ }).start();
+ }
+ count.await();
+ return builder.toString();
+ }
+
+ /**
+ * Get information with unirate.
+ *
+ * @return information
+ */
+ @GetMapping("/unirate")
+ public String unirate() throws InterruptedException {
+ StringBuffer builder = new StringBuffer();
+ CountDownLatch count = new CountDownLatch(30);
+ AtomicInteger index = new AtomicInteger(0);
+ long currentTimestamp = System.currentTimeMillis();
+ for (int i = 0; i < 30; i++) {
+ new Thread(() -> {
+ try {
+ long startTimestamp = System.currentTimeMillis();
+ ResponseEntity entity = restTemplate.getForEntity(
+ "http://QuickstartCalleeService/quickstart/callee/info", String.class);
+ long endTimestamp = System.currentTimeMillis();
+ builder.append("Start timestamp:" + startTimestamp + ". End timestamp: " + endTimestamp +
+ ". diff interval:" + (endTimestamp - startTimestamp) + "\n");
+ }
+ catch (RestClientException e) {
+ if (e instanceof HttpClientErrorException.TooManyRequests) {
+ builder.append("TooManyRequests " + index.incrementAndGet() + "\n");
+ }
+ else {
+ throw e;
+ }
+ }
+ count.countDown();
+ }).start();
+ }
+ count.await();
+ long lastTimestamp = System.currentTimeMillis();
+ builder.append("Unirate request from " + currentTimestamp + " to " + lastTimestamp + " with interval " + (lastTimestamp - currentTimestamp) + "ms.");
+
+ return builder.toString();
+ }
+
+ /**
+ * Get information of callee.
+ * @return information of callee
+ */
+ @GetMapping("/info")
+ public String info() {
+ LOG.info("Quickstart Callee Service is called.");
+ return "Quickstart Callee Service is called.";
+ }
+
+ /**
+ * health check.
+ * @return health check info
+ */
+ @GetMapping("/healthCheck")
+ public String healthCheck() {
+ return "ok";
+ }
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/resources/bootstrap.yml
new file mode 100644
index 000000000..33425c081
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/resources/bootstrap.yml
@@ -0,0 +1,41 @@
+server:
+ port: 48082
+spring:
+ application:
+ name: QuickstartCallerService
+ cloud:
+ polaris:
+ address: grpc://183.47.111.80:8091
+ namespace: default
+ enabled: true
+ discovery:
+ enabled: true
+ register: true
+ heartbeat:
+ enabled: true
+ health-check-url: /quickstart/caller/healthCheck
+ circuitbreaker:
+ enabled: true
+ stat:
+ enabled: true
+ port: 28081
+ # pushgateway:
+ # enabled: true
+ # address: 127.0.0.1:9091
+ tencent:
+ rpc-enhancement:
+ enabled: true
+ reporter:
+ enabled: true
+ ignore-internal-server-error: true
+ series: server_error
+ statuses: gateway_timeout, bad_gateway, service_unavailable
+feign:
+ hystrix:
+ enabled: true
+management:
+ endpoints:
+ web:
+ exposure:
+ include:
+ - polaris-discovery
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/resources/polaris.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/resources/polaris.yml
new file mode 100644
index 000000000..fbe20fc8f
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-caller-service/src/main/resources/polaris.yml
@@ -0,0 +1,14 @@
+consumer:
+ circuitBreaker:
+ checkPeriod: 100ms
+ chain:
+ - errorCount
+ - errorRate
+ plugin:
+ errorCount:
+ continuousErrorThreshold: 1
+ metricNumBuckets: 1
+ errorRate:
+ errorRateThreshold: 100
+ metricStatTimeWindow: 1s
+ requestVolumeThreshold: 1
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/pom.xml b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/pom.xml
new file mode 100644
index 000000000..fa916ec9e
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/pom.xml
@@ -0,0 +1,62 @@
+
+
+
+ quickstart-example
+ com.tencent.cloud
+ ${revision}
+ ../pom.xml
+
+ 4.0.0
+
+ quickstart-gateway-service
+ Quickstart Gateway Service
+
+
+
+ com.tencent.cloud
+ spring-cloud-starter-tencent-all
+ pom
+
+
+
+ com.tencent.cloud
+ spring-cloud-tencent-gateway-plugin
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-gateway
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+ repackage
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ 3.2.0
+
+
+ attach-sources
+
+ jar
+
+
+
+
+
+
+
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/src/main/java/com/tencent/cloud/quickstart/gateway/QuickstartGatewayApplication.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/src/main/java/com/tencent/cloud/quickstart/gateway/QuickstartGatewayApplication.java
new file mode 100644
index 000000000..5db23a74f
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/src/main/java/com/tencent/cloud/quickstart/gateway/QuickstartGatewayApplication.java
@@ -0,0 +1,35 @@
+/*
+ * 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.gateway;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * Quickstart SCG application.
+ *
+ * @author Haotian Zhang
+ */
+@SpringBootApplication
+public class QuickstartGatewayApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(QuickstartGatewayApplication.class, args);
+ }
+
+}
diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/src/main/resources/bootstrap.yml
new file mode 100644
index 000000000..fa49aa665
--- /dev/null
+++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-gateway-service/src/main/resources/bootstrap.yml
@@ -0,0 +1,28 @@
+server:
+ port: 48081
+spring:
+ application:
+ name: QuickStartGatewayService
+ cloud:
+ tencent:
+ plugin:
+ scg:
+ staining:
+ enabled: true
+ rule-staining:
+ enabled: true
+ router:
+ feature-env:
+ enabled: true
+ polaris:
+ address: grpc://183.47.111.80:8091
+ namespace: default
+ enabled: true
+ gateway:
+ routes:
+ - id: QuickstartCallerService
+ uri: lb://QuickstartCallerService
+ predicates:
+ - Path=/QuickstartCallerService/**
+ filters:
+ - StripPrefix=1
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java
index bfd13f5f8..3352362d7 100644
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java
+++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/config/RpcEnhancementAutoConfiguration.java
@@ -33,6 +33,7 @@ import com.tencent.polaris.api.core.ConsumerAPI;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
@@ -42,6 +43,8 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.context.annotation.Role;
import org.springframework.web.client.RestTemplate;
/**
@@ -65,6 +68,7 @@ public class RpcEnhancementAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(name = "org.springframework.cloud.openfeign.FeignAutoConfiguration")
@AutoConfigureBefore(name = "org.springframework.cloud.openfeign.FeignAutoConfiguration")
+ @Role(RootBeanDefinition.ROLE_INFRASTRUCTURE)
protected static class PolarisFeignClientAutoConfiguration {
@Bean
@@ -74,7 +78,7 @@ public class RpcEnhancementAutoConfiguration {
}
@Bean
- public EnhancedFeignBeanPostProcessor polarisFeignBeanPostProcessor(EnhancedFeignPluginRunner pluginRunner) {
+ public EnhancedFeignBeanPostProcessor polarisFeignBeanPostProcessor(@Lazy EnhancedFeignPluginRunner pluginRunner) {
return new EnhancedFeignBeanPostProcessor(pluginRunner);
}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java
index b870f3292..1f1c4366b 100644
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java
+++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/ExceptionPolarisReporter.java
@@ -42,12 +42,10 @@ import org.springframework.core.Ordered;
public class ExceptionPolarisReporter implements EnhancedFeignPlugin {
private static final Logger LOG = LoggerFactory.getLogger(ExceptionPolarisReporter.class);
-
+ private final RpcEnhancementReporterProperties reporterProperties;
@Autowired(required = false)
private ConsumerAPI consumerAPI;
- private RpcEnhancementReporterProperties reporterProperties;
-
public ExceptionPolarisReporter(RpcEnhancementReporterProperties reporterProperties) {
this.reporterProperties = reporterProperties;
}
@@ -79,6 +77,9 @@ public class ExceptionPolarisReporter implements EnhancedFeignPlugin {
LOG.debug("Will report result of {}. Request=[{}]. Response=[{}].", retStatus.name(), request, response);
ServiceCallResult resultRequest = ReporterUtils.createServiceCallResult(request, retStatus);
consumerAPI.updateServiceCallResult(resultRequest);
+ // update result without method for service circuit break.
+ resultRequest.setMethod("");
+ consumerAPI.updateServiceCallResult(resultRequest);
}
}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java
index eadaeaaf7..f7d59b512 100644
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java
+++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/feign/plugin/reporter/SuccessPolarisReporter.java
@@ -75,6 +75,9 @@ public class SuccessPolarisReporter extends AbstractPolarisReporterAdapter imple
LOG.debug("Will report result of {}. Request=[{}]. Response=[{}].", retStatus.name(), request, response);
ServiceCallResult resultRequest = ReporterUtils.createServiceCallResult(request, retStatus);
consumerAPI.updateServiceCallResult(resultRequest);
+ // update result without method for service circuit break.
+ resultRequest.setMethod("");
+ consumerAPI.updateServiceCallResult(resultRequest);
}
}
diff --git a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java
index 2a56c39bb..06379a8c5 100644
--- a/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java
+++ b/spring-cloud-tencent-rpc-enhancement/src/main/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporter.java
@@ -133,6 +133,9 @@ public class EnhancedRestTemplateReporter extends AbstractPolarisReporterAdapter
LOGGER.debug("Will report result of {}. URL=[{}]. Response=[{}].", resultRequest.getRetStatus().name(),
url, response);
consumerAPI.updateServiceCallResult(resultRequest);
+ // update result without method for service circuit break.
+ resultRequest.setMethod("");
+ consumerAPI.updateServiceCallResult(resultRequest);
}
catch (Exception e) {
LOGGER.error("RestTemplate response reporter execute failed of {} url {}", response, url, e);
diff --git a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java
index 173cb727d..099f266d8 100644
--- a/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java
+++ b/spring-cloud-tencent-rpc-enhancement/src/test/java/com/tencent/cloud/rpc/enhancement/resttemplate/EnhancedRestTemplateReporterTest.java
@@ -121,7 +121,7 @@ public class EnhancedRestTemplateReporterTest {
URI uri = mock(URI.class);
enhancedRestTemplateReporter.handleError(uri, HttpMethod.GET, response);
- verify(consumerAPI).updateServiceCallResult(any());
+ verify(consumerAPI, times(2)).updateServiceCallResult(any());
verify(delegate).handleError(uri, HttpMethod.GET, response);
}
@@ -136,7 +136,7 @@ public class EnhancedRestTemplateReporterTest {
URI uri = mock(URI.class);
enhancedRestTemplateReporter.handleError(uri, HttpMethod.GET, response);
- verify(consumerAPI).updateServiceCallResult(any());
+ verify(consumerAPI, times(2)).updateServiceCallResult(any());
verify(delegate, times(0)).handleError(uri, HttpMethod.GET, response);
}