From d1cf8ef4784c878ddd5a143bc8bdbf6d74fb5ce3 Mon Sep 17 00:00:00 2001 From: Haotian Zhang Date: Sat, 29 Mar 2025 16:49:23 +0800 Subject: [PATCH] docs:update circuit breaker examples. (#1521) --- CHANGELOG.md | 3 ++- .../callee/QuickstartCalleeController.java | 25 ++++++++++--------- .../src/main/resources/bootstrap.yml | 4 +++ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40427df17..80df27c4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,4 +21,5 @@ - [feat:upgrade trace plugin.](https://github.com/Tencent/spring-cloud-tencent/pull/1467) - [feat:upgrade 2.0.0 service.](https://github.com/Tencent/spring-cloud-tencent/pull/1471) - [fix:fix zuul delay circuit breaker.](https://github.com/Tencent/spring-cloud-tencent/pull/1519) -- [fix:fix watch tsf config, fix bean refresh with RefreshScope and ConfigurationProperties.](https://github.com/Tencent/spring-cloud-tencent/pull/1520) \ No newline at end of file +- [fix:fix watch tsf config, fix bean refresh with RefreshScope and ConfigurationProperties.](https://github.com/Tencent/spring-cloud-tencent/pull/1520) +- [docs:update circuit breaker examples.](https://github.com/Tencent/spring-cloud-tencent/pull/1521) diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java index 6d9a976b1..396a3fd0f 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/QuickstartCalleeController.java @@ -61,7 +61,7 @@ public class QuickstartCalleeController { @Autowired private DataSourceProperties dataSourceProperties; private boolean ifBadGateway = true; - private boolean ifDelay = false; + private int delay = 0; /** * Get sum of two value. @@ -111,8 +111,8 @@ public class QuickstartCalleeController { 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); + if (delay > 0) { + Thread.sleep(delay); 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); } @@ -131,8 +131,8 @@ public class QuickstartCalleeController { LOG.info("Quickstart Callee Service with uid {} [{}:{}] is called wrong.", uid, ip, port); return new ResponseEntity<>("failed for call quickstart callee service wildcard.", HttpStatus.BAD_GATEWAY); } - if (ifDelay) { - Thread.sleep(200); + if (delay > 0) { + Thread.sleep(delay); LOG.info("Quickstart Callee Service uid {} [{}:{}] is called slow.", uid, ip, port); return new ResponseEntity<>(String.format("Quickstart Callee Service [%s:%s] is called slow.", ip, port), HttpStatus.OK); } @@ -154,13 +154,14 @@ public class QuickstartCalleeController { } @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."; + public String setDelay(@RequestParam int param) { + this.delay = param; + if (delay > 0) { + LOG.info("info is set to delay {}ms.", delay); + return "info is set to delay " + delay + "ms."; } else { + delay = 0; LOG.info("info is set to no delay."); return "info is set to no delay."; } @@ -172,8 +173,8 @@ public class QuickstartCalleeController { 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); + if (delay > 0) { + Thread.sleep(delay); 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); } diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-zuul-service/src/main/resources/bootstrap.yml b/spring-cloud-tencent-examples/quickstart-example/quickstart-zuul-service/src/main/resources/bootstrap.yml index 903f6009d..315268626 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-zuul-service/src/main/resources/bootstrap.yml +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-zuul-service/src/main/resources/bootstrap.yml @@ -26,3 +26,7 @@ zuul: QuickstartCalleeService: serviceId: QuickstartCalleeService path: /QuickstartCalleeService/** + +ribbon: + ConnectTimeout: 10000 + ReadTimeout: 10000 \ No newline at end of file