From 0726eb77c06e5575af89d3c802e16a1b2f3959d9 Mon Sep 17 00:00:00 2001 From: coopermeng Date: Tue, 15 Jul 2025 20:47:05 +0800 Subject: [PATCH] feat:Add log output in the FaultToleranceService.java file and modify the response --- .../callee/service/FaultToleranceService.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/service/FaultToleranceService.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/service/FaultToleranceService.java index 446d53318..c596c7aa8 100644 --- a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/service/FaultToleranceService.java +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-a/src/main/java/com/tencent/cloud/quickstart/callee/service/FaultToleranceService.java @@ -21,6 +21,8 @@ import java.util.concurrent.atomic.AtomicInteger; import com.tencent.cloud.plugin.faulttolerance.annotation.FaultTolerance; import com.tencent.cloud.plugin.faulttolerance.model.FaultToleranceStrategy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -32,30 +34,35 @@ import org.springframework.stereotype.Service; @Service public class FaultToleranceService { + private static final Logger LOG = LoggerFactory.getLogger(FaultToleranceService.class); + private final AtomicInteger failOverCount = new AtomicInteger(0); private final AtomicInteger forkingCount = new AtomicInteger(0); @FaultTolerance(strategy = FaultToleranceStrategy.FAIL_FAST, fallbackMethod = "fallback") public String failFast() { + LOG.info("Test failFast"); throw new RuntimeException("NO"); } public String fallback() { - return "fallback"; + return "fallback success"; } @FaultTolerance(strategy = FaultToleranceStrategy.FAIL_OVER, maxAttempts = 3) public String failOver() { + LOG.info("Test failOver"); if (failOverCount.incrementAndGet() % 4 == 0) { - return "OK"; + return "failOver success"; } throw new RuntimeException("NO"); } @FaultTolerance(strategy = FaultToleranceStrategy.FORKING, parallelism = 4) public String forking() { + LOG.info("Test forking"); if (forkingCount.incrementAndGet() % 4 == 0) { - return "OK"; + return "forking success"; } throw new RuntimeException("NO"); }