From c4470461565e94c1369378ec891fe21e54c023e2 Mon Sep 17 00:00:00 2001 From: luyanbo Date: Mon, 25 Dec 2023 14:57:59 +0800 Subject: [PATCH] fix compile error --- mse-simple-demo/C/pom.xml | 12 +++++----- .../alibabacloud/mse/demo/c/CController.java | 22 ++++++++++++++++--- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/mse-simple-demo/C/pom.xml b/mse-simple-demo/C/pom.xml index f0384bd9..47efdd6d 100644 --- a/mse-simple-demo/C/pom.xml +++ b/mse-simple-demo/C/pom.xml @@ -96,17 +96,17 @@ 1.4.199 - - com.alibaba.csp - spring-boot-starter-ahas-sentinel-client - 1.10.11 - - mysql mysql-connector-java 8.0.31 + + + com.alibaba.csp + sentinel-core + 1.8.6 + diff --git a/mse-simple-demo/C/src/main/java/com/alibabacloud/mse/demo/c/CController.java b/mse-simple-demo/C/src/main/java/com/alibabacloud/mse/demo/c/CController.java index 24a11685..5cd7d185 100644 --- a/mse-simple-demo/C/src/main/java/com/alibabacloud/mse/demo/c/CController.java +++ b/mse-simple-demo/C/src/main/java/com/alibabacloud/mse/demo/c/CController.java @@ -1,5 +1,10 @@ package com.alibabacloud.mse.demo.c; +import com.alibaba.csp.sentinel.Entry; +import com.alibaba.csp.sentinel.EntryType; +import com.alibaba.csp.sentinel.SphU; +import com.alibaba.csp.sentinel.slots.block.BlockException; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.config.RequestConfig; @@ -21,6 +26,7 @@ import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; +@Slf4j @RestController class CController { @@ -90,9 +96,19 @@ public String spring_boot(HttpServletRequest request) { @GetMapping("/flow") public String flow(HttpServletRequest request) throws ExecutionException, InterruptedException { - long sleepTime = 5 + RANDOM.nextInt(5); - silentSleep(sleepTime); - return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime; + try (Entry entry1 = SphU.entry("HelloWorld-c-flow-1", EntryType.IN)) { + log.debug("Hello Sentinel!1"); + try (Entry entry2 = SphU.entry("H\"elloWorld-c-flow-2", EntryType.IN)) { + log.debug("Hello Sentinel!2"); + long sleepTime = 5 + RANDOM.nextInt(5); + silentSleep(sleepTime); + return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime; + } catch (BlockException e) { + throw new RuntimeException(e); + } + } catch (BlockException e) { + throw new RuntimeException(e); + } } @GetMapping("/params/{hot}")