From 2a3b9e0e462e8a587ea23a497fb86c5a99c176da Mon Sep 17 00:00:00 2001 From: fredrikliu Date: Tue, 14 May 2024 12:17:04 +0800 Subject: [PATCH] add circuitbreaker example --- .../quickstart-callee-service-a/Dockerfile | 29 +++ .../deployment.yaml | 48 +++++ .../quickstart-callee-service-a/pom.xml | 82 ++++++++ .../quickstart/callee/CustomMetadata.java | 46 +++++ .../callee/QuickstartCalleeController.java | 136 +++++++++++++ .../callee/QuickstartCalleeServiceA.java | 34 ++++ .../config/CustomConfigChangeListener.java | 51 +++++ .../callee/config/DataSourceProperties.java | 65 +++++++ .../callee/ratelimit/CustomLabelResolver.java | 63 ++++++ .../src/main/resources/bootstrap.yml | 48 +++++ .../src/main/resources/reject-tips.html | 5 + .../quickstart-callee-service-b/Dockerfile | 29 +++ .../deployment.yaml | 48 +++++ .../quickstart-callee-service-b/pom.xml | 82 ++++++++ .../quickstart/callee/CustomMetadata.java | 46 +++++ .../callee/QuickstartCalleeController.java | 162 ++++++++++++++++ .../callee/QuickstartCalleeServiceB.java | 34 ++++ .../config/CustomConfigChangeListener.java | 51 +++++ .../callee/config/DataSourceProperties.java | 65 +++++++ .../CustomLabelResolverReactive.java | 60 ++++++ ...JsonPolarisRateLimiterLimitedFallback.java | 41 ++++ .../src/main/resources/bootstrap.yml | 47 +++++ .../quickstart-caller-service/Dockerfile | 29 +++ .../quickstart-caller-service/deployment.yaml | 48 +++++ .../quickstart-caller-service/pom.xml | 92 +++++++++ .../caller/CustomMetadataProvider.java | 34 ++++ .../caller/QuickstartCalleeService.java | 41 ++++ .../QuickstartCalleeServiceFallback.java | 34 ++++ .../caller/QuickstartCallerApplication.java | 85 ++++++++ .../caller/QuickstartCallerController.java | 182 ++++++++++++++++++ .../CircuitBreakerController.java | 136 +++++++++++++ ...CircuitBreakerQuickstartCalleeService.java | 38 ++++ ...reakerQuickstartCalleeServiceFallback.java | 34 ++++ ...erQuickstartCalleeServiceWithFallback.java | 38 ++++ .../caller/circuitbreaker/CustomFallback.java | 43 +++++ .../router/CustomRouterLabelResolver.java | 54 ++++++ .../src/main/resources/bootstrap.yml | 46 +++++ 37 files changed, 2206 insertions(+) create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceA.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolver.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/bootstrap.yml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/reject-tips.html create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceB.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolverReactive.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/JsonPolarisRateLimiterLimitedFallback.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/resources/bootstrap.yml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/Dockerfile create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/deployment.yaml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/pom.xml create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/CustomMetadataProvider.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CustomFallback.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/router/CustomRouterLabelResolver.java create mode 100644 polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/resources/bootstrap.yml diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/deployment.yaml new file mode 100644 index 00000000..09bf138b --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: hoxton-callee-a + name: hoxton-callee-a + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: hoxton-callee-a + template: + metadata: + labels: + app: hoxton-callee-a + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC2" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "hoxton" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-hoxton-callee-a:1.7.0-java8 + imagePullPolicy: Always + name: provider + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65007 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/pom.xml new file mode 100644 index 00000000..53056897 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/pom.xml @@ -0,0 +1,82 @@ + + + + quickstart-example + com.tencent.cloud + 1.14.0-Hoxton.SR12-SNAPSHOT + + + 4.0.0 + + quickstart-callee-service-a + Quickstart Callee Service A + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR12 + pom + import + + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-all + 1.14.0-Hoxton.SR12-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java new file mode 100644 index 00000000..bdd60f8e --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/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/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java new file mode 100644 index 00000000..ce586e97 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java @@ -0,0 +1,136 @@ +/* + * 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.io.UnsupportedEncodingException; +import java.net.URLDecoder; + +import com.tencent.cloud.common.constant.MetadataConstant; +import com.tencent.cloud.quickstart.callee.config.DataSourceProperties; +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.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import static com.tencent.cloud.common.constant.ContextConstant.UTF_8; + +/** + * 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("${spring.cloud.client.ip-address:127.0.0.1}") + private String ip; + + @Value("${appName:${spring.application.name}}") + private String appName; + + @Autowired + private DataSourceProperties dataSourceProperties; + + /** + * Get sum of two value. + * @param value1 value 1 + * @param value2 value 2 + * @return sum + */ + @GetMapping("/sum") + public String sum(@RequestParam int value1, @RequestParam int value2) { + LOG.info("Quickstart Callee Service [{}:{}] is called and sum is [{}].", ip, port, value1 + value2); + return String.format("Quickstart Callee Service [%s:%s] is called and sum is [%s].", ip, port, value1 + value2); + } + + /** + * Get information of callee. + * @return information of callee + */ + @GetMapping("/info") + public String info() { + LOG.info("Quickstart [{}] Service [{}:{}] is called. datasource = [{}].", appName, ip, port, dataSourceProperties); + return String.format("Quickstart [%s] Service [%s:%s] is called. datasource = [%s].", appName, ip, port, dataSourceProperties); + } + + /** + * Mock post save value. + * @return true + */ + @PostMapping("/saveValue") + public Boolean saveValue(@RequestParam int value) { + LOG.info("Quickstart [{}] Service [{}:{}] is called. Mock save value = [{}].", appName, ip, port, value); + return true; + } + + /** + * Get path echo of callee. + * @return information of callee + */ + @GetMapping("/path/echo/{param}") + public String pathEcho(@PathVariable String param) { + LOG.info("Quickstart [{}] Service [{}:{}] is called. param = [{}].", appName, ip, port, param); + return String.format("Quickstart [%s] Service [%s:%s] is called. datasource = [%s].", appName, ip, port, param); + } + + /** + * Get metadata in HTTP header. + * + * @param metadataStr metadata string + * @return metadata in HTTP header + * @throws UnsupportedEncodingException encoding exception + */ + @RequestMapping("/echo") + public String echoHeader(@RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String metadataStr) + throws UnsupportedEncodingException { + LOG.info(URLDecoder.decode(metadataStr, UTF_8)); + metadataStr = URLDecoder.decode(metadataStr, UTF_8); + return metadataStr; + } + + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/circuitBreak") + public String circuitBreak() { + LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port); + return String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port); + } + + @GetMapping("/faultDetect") + public String health() { + LOG.info("Quickstart Callee Service [{}:{}] is detected right.", ip, port); + return String.format("Quickstart Callee Service [%s:%s] is detected right.", ip, port); + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceA.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceA.java new file mode 100644 index 00000000..fb00d56e --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/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/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java new file mode 100644 index 00000000..bd2b1295 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java @@ -0,0 +1,51 @@ +/* + * 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.config; + +import java.util.Set; + +import com.tencent.cloud.polaris.config.annotation.PolarisConfigKVFileChangeListener; +import com.tencent.cloud.polaris.config.listener.ConfigChangeEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.stereotype.Component; + +/** + * Custom Config Listener Example . + * + * @author Haotian Zhang + */ +@Component +public final class CustomConfigChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(CustomConfigChangeListener.class); + + /** + * PolarisConfigKVFileChangeListener Example . + * @param event instance of {@link ConfigChangeEvent} + */ + @PolarisConfigKVFileChangeListener(interestedKeyPrefixes = "appName") + public void onChange(ConfigChangeEvent event) { + Set changedKeys = event.changedKeys(); + + for (String changedKey : changedKeys) { + LOG.info("{} = {}", changedKey, event.getChange(changedKey)); + } + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java new file mode 100644 index 00000000..00ac6717 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java @@ -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.config; + +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 + '\''; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolver.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolver.java new file mode 100644 index 00000000..cdd4b97e --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolver.java @@ -0,0 +1,63 @@ +/* + * 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.ratelimit; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import com.tencent.cloud.polaris.ratelimit.spi.PolarisRateLimiterLabelServletResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * resolver custom label from request. + * + * @author lepdou 2022-03-31 + */ +@Component +public class CustomLabelResolver implements PolarisRateLimiterLabelServletResolver { + private static final Logger LOG = LoggerFactory.getLogger(CustomLabelResolver.class); + + @Value("${label.key-value:}") + private String[] keyValues; + + @Override + public Map resolve(HttpServletRequest request) { + // rate limit by some request params. such as query params, headers .. + + return getLabels(keyValues); + } + + private Map getLabels(String[] keyValues) { + Map labels = new HashMap<>(); + for (String kv : keyValues) { + String key = kv.substring(0, kv.indexOf(":")); + String value = kv.substring(kv.indexOf(":") + 1); + labels.put(key, value); + } + + LOG.info("Current labels:{}", labels); + return labels; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/bootstrap.yml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..7701d56e --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/bootstrap.yml @@ -0,0 +1,48 @@ +server: + port: 48083 +spring: + application: + name: QuickstartCalleeService + cloud: + polaris: + address: grpc://106.55.74.24:8091 + namespace: default + enabled: true + discovery: + enabled: true + register: true + contract: + exposure: true + report: + enabled: false + stat: + enabled: true + port: 28083 + # pushgateway: + # enabled: true + # address: 127.0.0.1:9091 + config: + address: grpc://106.55.74.24:8093 + auto-refresh: true + groups: + - name: ${spring.application.name} + files: [ "config/callee.properties" ] + ratelimit: + enabled: true + rejectRequestTipsFilePath: reject-tips.html + maxQueuingTime: 500 + tencent: + metadata: + content: + label1: value1 + region: huanan +management: + endpoints: + web: + exposure: + include: + - polaris-discovery + - polaris-ratelimit + - polaris-config +label: + key-value: user:zhangsan diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/reject-tips.html b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/reject-tips.html new file mode 100644 index 00000000..693ef256 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-a/src/main/resources/reject-tips.html @@ -0,0 +1,5 @@ +

+ + Custom reject content. + +

diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/deployment.yaml new file mode 100644 index 00000000..880fcdcf --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: hoxton-callee-b + name: hoxton-callee-b + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: hoxton-callee-b + template: + metadata: + labels: + app: hoxton-callee-b + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC2" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "hoxton" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-hoxton-callee-b:1.7.0-java8 + imagePullPolicy: Always + name: provider + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65008 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/pom.xml new file mode 100644 index 00000000..c8a195c3 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/pom.xml @@ -0,0 +1,82 @@ + + + + quickstart-example + com.tencent.cloud + 1.14.0-Hoxton.SR12-SNAPSHOT + + + 4.0.0 + + quickstart-callee-service-b + Quickstart Callee Service B + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR12 + pom + import + + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-all + 1.14.0-Hoxton.SR12-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/CustomMetadata.java new file mode 100644 index 00000000..8257f2cd --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/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/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java new file mode 100644 index 00000000..d4de94f3 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java @@ -0,0 +1,162 @@ +/* + * 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.io.UnsupportedEncodingException; +import java.net.URLDecoder; + +import com.tencent.cloud.common.constant.MetadataConstant; +import com.tencent.cloud.quickstart.callee.config.DataSourceProperties; +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.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import static com.tencent.cloud.common.constant.ContextConstant.UTF_8; + +/** + * 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("${spring.cloud.client.ip-address:127.0.0.1}") + private String ip; + + @Value("${appName:${spring.application.name}}") + private String appName; + + @Autowired + private DataSourceProperties dataSourceProperties; + private boolean ifBadGateway = true; + private boolean ifDelay = true; + + /** + * Get sum of two value. + * @param value1 value 1 + * @param value2 value 2 + * @return sum + */ + @GetMapping("/sum") + public String sum(@RequestParam int value1, @RequestParam int value2) { + LOG.info("Quickstart Callee Service [{}:{}] is called and sum is [{}].", ip, port, value1 + value2); + return String.format("Quickstart Callee Service [%s:%s] is called and sum is [%s].", ip, port, value1 + value2); + } + + /** + * Get information of callee. + * @return information of callee + */ + @GetMapping("/info") + public String info() { + LOG.info("Quickstart [{}] Service [{}:{}] is called. datasource = [{}].", appName, ip, port, dataSourceProperties); + return String.format("Quickstart [%s] Service [%s:%s] is called. datasource = [%s].", appName, ip, port, dataSourceProperties); + } + + /** + * Get metadata in HTTP header. + * + * @param metadataStr metadata string + * @return metadata in HTTP header + * @throws UnsupportedEncodingException encoding exception + */ + @RequestMapping("/echo") + public String echoHeader(@RequestHeader(MetadataConstant.HeaderName.CUSTOM_METADATA) String metadataStr) + throws UnsupportedEncodingException { + LOG.info(URLDecoder.decode(metadataStr, UTF_8)); + metadataStr = URLDecoder.decode(metadataStr, UTF_8); + return metadataStr; + } + + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/circuitBreak") + public ResponseEntity circuitBreak() throws InterruptedException { + if (ifBadGateway) { + LOG.info("Quickstart Callee Service [{}:{}] is called wrong.", ip, port); + return new ResponseEntity<>("failed for call quickstart callee service.", HttpStatus.BAD_GATEWAY); + } + if (ifDelay) { + Thread.sleep(200); + LOG.info("Quickstart Callee Service [{}:{}] is called slow.", ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); + } + LOG.info("Quickstart Callee Service [{}:{}] is called right.", ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called right.", ip, port), HttpStatus.OK); + } + + @GetMapping("/setBadGateway") + public String setBadGateway(@RequestParam boolean param) { + this.ifBadGateway = param; + if (param) { + LOG.info("info is set to return HttpStatus.BAD_GATEWAY."); + return "info is set to return HttpStatus.BAD_GATEWAY."; + } + else { + LOG.info("info is set to return HttpStatus.OK."); + return "info is set to return HttpStatus.OK."; + } + } + + @GetMapping("/setDelay") + public String setDelay(@RequestParam boolean param) { + this.ifDelay = param; + if (param) { + LOG.info("info is set to delay 200ms."); + return "info is set to delay 200ms."; + } + else { + LOG.info("info is set to no delay."); + return "info is set to no delay."; + } + } + + @GetMapping("/faultDetect") + public ResponseEntity health() throws InterruptedException { + if (ifBadGateway) { + LOG.info("Quickstart Callee Service [{}:{}] is detected wrong.", ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected wrong.", ip, port), HttpStatus.BAD_GATEWAY); + } + if (ifDelay) { + Thread.sleep(200); + LOG.info("Quickstart Callee Service [{}:{}] is detected slow.", ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected slow.", ip, port), HttpStatus.OK); + } + LOG.info("Quickstart Callee Service [{}:{}] is detected right.", ip, port); + return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is detected right.", ip, port), HttpStatus.OK); + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceB.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeServiceB.java new file mode 100644 index 00000000..c2740e40 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/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/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java new file mode 100644 index 00000000..bd2b1295 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/CustomConfigChangeListener.java @@ -0,0 +1,51 @@ +/* + * 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.config; + +import java.util.Set; + +import com.tencent.cloud.polaris.config.annotation.PolarisConfigKVFileChangeListener; +import com.tencent.cloud.polaris.config.listener.ConfigChangeEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.stereotype.Component; + +/** + * Custom Config Listener Example . + * + * @author Haotian Zhang + */ +@Component +public final class CustomConfigChangeListener { + + private static final Logger LOG = LoggerFactory.getLogger(CustomConfigChangeListener.class); + + /** + * PolarisConfigKVFileChangeListener Example . + * @param event instance of {@link ConfigChangeEvent} + */ + @PolarisConfigKVFileChangeListener(interestedKeyPrefixes = "appName") + public void onChange(ConfigChangeEvent event) { + Set changedKeys = event.changedKeys(); + + for (String changedKey : changedKeys) { + LOG.info("{} = {}", changedKey, event.getChange(changedKey)); + } + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java new file mode 100644 index 00000000..00ac6717 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/config/DataSourceProperties.java @@ -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.config; + +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 + '\''; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolverReactive.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolverReactive.java new file mode 100644 index 00000000..4a270fc6 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/CustomLabelResolverReactive.java @@ -0,0 +1,60 @@ +/* + * 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.ratelimit; + +import java.util.HashMap; +import java.util.Map; + +import com.tencent.cloud.polaris.ratelimit.spi.PolarisRateLimiterLabelReactiveResolver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import org.springframework.web.server.ServerWebExchange; + +/** + * resolver custom label from request. + * + * @author sean yu + */ +@Component +public class CustomLabelResolverReactive implements PolarisRateLimiterLabelReactiveResolver { + private static final Logger LOG = LoggerFactory.getLogger(CustomLabelResolverReactive.class); + + @Value("${label.key-value:}") + private String[] keyValues; + + @Override + public Map resolve(ServerWebExchange exchange) { + // rate limit by some request params. such as query params, headers .. + return getLabels(keyValues); + } + + private Map getLabels(String[] keyValues) { + Map labels = new HashMap<>(); + for (String kv : keyValues) { + String key = kv.substring(0, kv.indexOf(":")); + String value = kv.substring(kv.indexOf(":") + 1); + labels.put(key, value); + } + + LOG.info("Current labels:{}", labels); + return labels; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/JsonPolarisRateLimiterLimitedFallback.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/JsonPolarisRateLimiterLimitedFallback.java new file mode 100644 index 00000000..9c871287 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/ratelimit/JsonPolarisRateLimiterLimitedFallback.java @@ -0,0 +1,41 @@ +/* + * 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.ratelimit; + +import com.tencent.cloud.polaris.ratelimit.spi.PolarisRateLimiterLimitedFallback; + +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +/** + * JsonPolarisRateLimiterLimitedFallback. + * + * @author Lingxiao.Wu + */ +@Component +public class JsonPolarisRateLimiterLimitedFallback implements PolarisRateLimiterLimitedFallback { + @Override + public MediaType mediaType() { + return MediaType.APPLICATION_JSON; + } + + @Override + public String rejectTips() { + return "{\"success\":false,\"code\":429,\"msg\":\"RejectRequestTips提示消息\",\"timestamp\":1673415310479}"; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/resources/bootstrap.yml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..1c9a63ba --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-callee-service-b/src/main/resources/bootstrap.yml @@ -0,0 +1,47 @@ +server: + port: 48084 +spring: + application: + name: QuickstartCalleeService + cloud: + polaris: + address: grpc://106.55.74.24:8091 + namespace: default + enabled: true + discovery: + enabled: true + register: true + contract: + exposure: true + report: + enabled: false + stat: + enabled: true + port: 28084 + # pushgateway: + # enabled: true + # address: 127.0.0.1:9091 + config: + address: grpc://106.55.74.24:8093 + auto-refresh: true + groups: + - name: ${spring.application.name} + files: [ "config/callee.properties" ] + ratelimit: + enabled: true + maxQueuingTime: 500 + tencent: + metadata: + content: + label1: value2 + region: huanan +management: + endpoints: + web: + exposure: + include: + - polaris-discovery + - polaris-ratelimit + - polaris-config +label: + key-value: user2:lisi diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/Dockerfile b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/Dockerfile new file mode 100644 index 00000000..e4da5f69 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/Dockerfile @@ -0,0 +1,29 @@ +FROM alpine:3.19.1 + +ARG file_name +ARG java_version + +COPY ./target/${file_name} /app/main.jar + +WORKDIR /app + +RUN sed -i 's!http://dl-cdn.alpinelinux.org/!https://mirrors.tencent.com/!g' /etc/apk/repositories + +RUN set -eux && \ + apk add openjdk${java_version} && \ + apk add bind-tools && \ + apk add busybox-extras && \ + apk add findutils && \ + apk add tcpdump && \ + apk add tzdata && \ + apk add curl && \ + apk add bash && \ + cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \ + echo "Asia/Shanghai" > /etc/timezone && \ + date + +RUN chmod 777 /app/ + +RUN ls -la /app/ + +ENTRYPOINT ["java", "-jar", "/app/main.jar"] \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/deployment.yaml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/deployment.yaml new file mode 100644 index 00000000..3f4cb46b --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/deployment.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: hoxton-caller + name: hoxton-caller + namespace: default +spec: + replicas: 1 + selector: + matchLabels: + app: hoxton-caller + template: + metadata: + labels: + app: hoxton-caller + annotations: + polarismesh.cn/javaagent: "true" + polarismesh.cn/javaagentVersion: "1.7.0-RC2" + polarismesh.cn/javaagentFrameworkName: "spring-cloud" + polarismesh.cn/javaagentFrameworkVersion: "hoxton" + spec: + containers: + - image: polarismesh/polaris-javaagent-demo-sc-quickstart-hoxton-caller:1.7.0-java8 + imagePullPolicy: Always + name: consumer + resources: + limits: + cpu: "500m" + memory: 1000Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + command: + - /bin/bash + - -c + - cd /app && java -Dserver.port=65008 -jar main.jar + lifecycle: + preStop: + exec: + command: ["curl","-X","PUT","http://127.0.0.1:28080/offline","&&","sleep","30"] + readinessProbe: + httpGet: + path: /online + port: 28080 + initialDelaySeconds: 3 + periodSeconds: 3 + restartPolicy: Always \ No newline at end of file diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/pom.xml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/pom.xml new file mode 100644 index 00000000..faeb6317 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/pom.xml @@ -0,0 +1,92 @@ + + + + quickstart-example + com.tencent.cloud + 1.14.0-Hoxton.SR12-SNAPSHOT + + + 4.0.0 + + quickstart-caller-service + Quickstart Caller Service + + + + + com.alibaba.cloud + spring-cloud-alibaba-dependencies + 2.2.1.RELEASE + pom + import + + + + org.springframework.cloud + spring-cloud-dependencies + Hoxton.SR12 + pom + import + + + + + + + com.tencent.cloud + spring-cloud-starter-tencent-all + 1.14.0-Hoxton.SR12-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.springframework.cloud + spring-cloud-starter-openfeign + + + + org.springframework.boot + spring-boot-starter-actuator + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + + org.apache.maven.plugins + maven-source-plugin + 3.2.0 + + + attach-sources + + jar + + + + + + + diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/CustomMetadataProvider.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/CustomMetadataProvider.java new file mode 100644 index 00000000..94829657 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/CustomMetadataProvider.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.caller; + +import com.tencent.cloud.common.spi.InstanceMetadataProvider; + +import org.springframework.stereotype.Component; + +/** + *@author lepdou 2022-06-29 + */ +@Component +public class CustomMetadataProvider implements InstanceMetadataProvider { + + @Override + public String getRegion() { + return "huadong"; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java new file mode 100644 index 00000000..f210fb54 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeService.java @@ -0,0 +1,41 @@ +/* + * 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") + String sum(@RequestParam("value1") int value1, @RequestParam("value2") int value2); +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.java new file mode 100644 index 00000000..8f680a8d --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCalleeServiceFallback.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.caller; + +import org.springframework.stereotype.Component; + +/** + * Quickstart callee feign client fallback. + * + * @author Haotian Zhang + */ +@Component +public class QuickstartCalleeServiceFallback implements QuickstartCalleeService { + + @Override + public String sum(int value1, int value2) { + return "sum is 0."; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java new file mode 100644 index 00000000..26fcb7ee --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerApplication.java @@ -0,0 +1,85 @@ +/* + * 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 com.tencent.cloud.polaris.circuitbreaker.resttemplate.PolarisCircuitBreaker; +import com.tencent.cloud.quickstart.caller.circuitbreaker.CustomFallback; + +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; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.util.DefaultUriBuilderFactory; + +/** + * 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(); + } + + @Bean + @LoadBalanced + public RestTemplate defaultRestTemplate() { + DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://QuickstartCalleeService"); + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(uriBuilderFactory); + return restTemplate; + } + + @Bean + @LoadBalanced + @PolarisCircuitBreaker + public RestTemplate restTemplateFallbackFromPolaris() { + DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://QuickstartCalleeService"); + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(uriBuilderFactory); + return restTemplate; + } + + @Bean + @LoadBalanced + @PolarisCircuitBreaker(fallbackClass = CustomFallback.class) + public RestTemplate restTemplateFallbackFromCode() { + DefaultUriBuilderFactory uriBuilderFactory = new DefaultUriBuilderFactory("http://QuickstartCalleeService"); + RestTemplate restTemplate = new RestTemplate(); + restTemplate.setUriTemplateHandler(uriBuilderFactory); + return restTemplate; + } + + @LoadBalanced + @Bean + WebClient.Builder webClientBuilder() { + return WebClient.builder().baseUrl("http://QuickstartCalleeService"); + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java new file mode 100644 index 00000000..ec939dd1 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/QuickstartCallerController.java @@ -0,0 +1,182 @@ +/* + * 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 reactor.core.publisher.Mono; + +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; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * 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; + + @Autowired + private WebClient.Builder webClientBuilder; + + /** + * Get sum of two value. + * @param value1 value 1 + * @param value2 value 2 + * @return sum + */ + @GetMapping("/feign") + public String 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("/webclient") + public Mono webclient() { + return webClientBuilder + .build() + .get() + .uri("/quickstart/callee/echo") + .retrieve() + .bodyToMono(String.class); + } + + /** + * 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 caller. + * @return information of caller + */ + @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/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java new file mode 100644 index 00000000..4d902aaa --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerController.java @@ -0,0 +1,136 @@ +/* + * 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.circuitbreaker; + +import reactor.core.publisher.Mono; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory; +import org.springframework.cloud.client.circuitbreaker.ReactiveCircuitBreakerFactory; +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.RestController; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.reactive.function.client.WebClient; + +/** + * Controller for circuit breaker. + * + * @author Haotian Zhang + */ +@RestController +@RequestMapping("/quickstart/caller/circuitBreak") +public class CircuitBreakerController { + + @Autowired + private CircuitBreakerQuickstartCalleeService circuitBreakerQuickstartCalleeService; + + @Autowired + private CircuitBreakerQuickstartCalleeServiceWithFallback circuitBreakerQuickstartCalleeServiceWithFallback; + + @Autowired + @Qualifier("defaultRestTemplate") + private RestTemplate defaultRestTemplate; + + @Autowired + @Qualifier("restTemplateFallbackFromPolaris") + private RestTemplate restTemplateFallbackFromPolaris; + + @Autowired + @Qualifier("restTemplateFallbackFromCode") + private RestTemplate restTemplateFallbackFromCode; + + @Autowired + private CircuitBreakerFactory circuitBreakerFactory; + + @Autowired + private ReactiveCircuitBreakerFactory reactiveCircuitBreakerFactory; + + @Autowired + private WebClient.Builder webClientBuilder; + + /** + * Feign circuit breaker with fallback from Polaris. + * @return circuit breaker information of callee + */ + @GetMapping("/feign/fallbackFromPolaris") + public String circuitBreakFeignFallbackFromPolaris() { + return circuitBreakerQuickstartCalleeService.circuitBreak(); + } + + /** + * Feign circuit breaker with fallback from Polaris. + * @return circuit breaker information of callee + */ + @GetMapping("/feign/fallbackFromCode") + public String circuitBreakFeignFallbackFromCode() { + return circuitBreakerQuickstartCalleeServiceWithFallback.circuitBreak(); + } + + /** + * RestTemplate circuit breaker. + * @return circuit breaker information of callee + */ + @GetMapping("/rest") + public String circuitBreakRestTemplate() { + return circuitBreakerFactory + .create("QuickstartCalleeService#/quickstart/callee/circuitBreak") + .run(() -> defaultRestTemplate.getForObject("/quickstart/callee/circuitBreak", String.class), + throwable -> "trigger the refuse for service callee." + ); + } + + /** + * RestTemplate circuit breaker with fallback from Polaris. + * @return circuit breaker information of callee + */ + @GetMapping("/rest/fallbackFromPolaris") + public ResponseEntity circuitBreakRestTemplateFallbackFromPolaris() { + return restTemplateFallbackFromPolaris.getForEntity("/quickstart/callee/circuitBreak", String.class); + } + + /** + * RestTemplate circuit breaker with fallback from code. + * @return circuit breaker information of callee + */ + @GetMapping("/rest/fallbackFromCode") + public ResponseEntity circuitBreakRestTemplateFallbackFromCode() { + return restTemplateFallbackFromCode.getForEntity("/quickstart/callee/circuitBreak", String.class); + } + + /** + * Get information of callee. + * @return information of callee + */ + @GetMapping("/webclient") + public Mono webclient() { + return webClientBuilder + .build() + .get() + .uri("/quickstart/callee/circuitBreak") + .retrieve() + .bodyToMono(String.class) + .transform(it -> + reactiveCircuitBreakerFactory + .create("QuickstartCalleeService#/quickstart/callee/circuitBreak") + .run(it, throwable -> Mono.just("fallback: trigger the refuse for service callee")) + ); + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java new file mode 100644 index 00000000..64821b9a --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeService.java @@ -0,0 +1,38 @@ +/* + * 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.circuitbreaker; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * Circuit breaker example callee provider. + * + * @author sean yu + */ +@FeignClient(name = "QuickstartCalleeService", contextId = "fallback-from-polaris") +public interface CircuitBreakerQuickstartCalleeService { + + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/quickstart/callee/circuitBreak") + String circuitBreak(); +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.java new file mode 100644 index 00000000..06a2df36 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceFallback.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.caller.circuitbreaker; + +import org.springframework.stereotype.Component; + +/** + * Circuit breaker example callee fallback. + * + * @author sean yu + */ +@Component +public class CircuitBreakerQuickstartCalleeServiceFallback implements CircuitBreakerQuickstartCalleeServiceWithFallback { + + @Override + public String circuitBreak() { + return "fallback: trigger the refuse for service callee."; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java new file mode 100644 index 00000000..f71a7650 --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CircuitBreakerQuickstartCalleeServiceWithFallback.java @@ -0,0 +1,38 @@ +/* + * 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.circuitbreaker; + +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * CircuitBreakerQuickstartCalleeServiceWithFallback. + * + * @author sean yu + */ +@FeignClient(name = "QuickstartCalleeService", contextId = "fallback-from-code", fallback = CircuitBreakerQuickstartCalleeServiceFallback.class) +public interface CircuitBreakerQuickstartCalleeServiceWithFallback { + + /** + * Check circuit break. + * + * @return circuit break info + */ + @GetMapping("/quickstart/callee/circuitBreak") + String circuitBreak(); +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CustomFallback.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CustomFallback.java new file mode 100644 index 00000000..887d690d --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/circuitbreaker/CustomFallback.java @@ -0,0 +1,43 @@ +/* + * 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.circuitbreaker; + +import java.util.HashMap; + +import com.tencent.cloud.polaris.circuitbreaker.resttemplate.PolarisCircuitBreakerFallback; +import com.tencent.cloud.polaris.circuitbreaker.resttemplate.PolarisCircuitBreakerHttpResponse; + +import org.springframework.stereotype.Component; + +/** + * CustomFallback. + * + * @author sean yu + */ +@Component +public class CustomFallback implements PolarisCircuitBreakerFallback { + @Override + public PolarisCircuitBreakerHttpResponse fallback() { + return new PolarisCircuitBreakerHttpResponse( + 200, + new HashMap() {{ + put("Content-Type", "application/json"); + }}, + "{\"msg\": \"this is a fallback class\"}"); + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/router/CustomRouterLabelResolver.java b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/router/CustomRouterLabelResolver.java new file mode 100644 index 00000000..18f3d0ca --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/java/com/tencent/cloud/quickstart/caller/router/CustomRouterLabelResolver.java @@ -0,0 +1,54 @@ +/* + * 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.router; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import com.google.gson.Gson; +import com.tencent.cloud.polaris.router.spi.FeignRouterLabelResolver; +import feign.RequestTemplate; + +import org.springframework.stereotype.Component; + +/** + * + * Customize the business tag information obtained from the request + * + *@author lepdou 2022-05-12 + */ +@Component +public class CustomRouterLabelResolver implements FeignRouterLabelResolver { + private final Gson gson = new Gson(); + + @Override + public Map resolve(RequestTemplate requestTemplate, Set expressionLabelKeys) { + Map labels = new HashMap<>(); + + labels.put("label1", "value1"); + + return labels; + } + + @Override + public int getOrder() { + return 0; + } +} diff --git a/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/resources/bootstrap.yml b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/resources/bootstrap.yml new file mode 100644 index 00000000..58cfd4eb --- /dev/null +++ b/polaris-agent-examples/spring-cloud-plugins-examples/spring-cloud-hoxton-examples/quickstart-examples/quickstart-caller-service/src/main/resources/bootstrap.yml @@ -0,0 +1,46 @@ +server: + port: 48082 +spring: + application: + name: QuickstartCallerService + cloud: + polaris: + address: grpc://106.55.74.24:8091 + namespace: default + enabled: true + discovery: + enabled: true + register: true + heartbeat: + enabled: true + health-check-url: /quickstart/caller/healthCheck + contract: + exposure: true + report: + enabled: false + circuitbreaker: + enabled: true + stat: + enabled: true + port: 28082 + # 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 + - polaris-circuit-breaker