|
1 | 1 | package com.alibabacloud.mse.demo.c; |
2 | 2 |
|
| 3 | +import com.alibaba.csp.sentinel.Entry; |
| 4 | +import com.alibaba.csp.sentinel.EntryType; |
| 5 | +import com.alibaba.csp.sentinel.SphU; |
| 6 | +import com.alibaba.csp.sentinel.slots.block.BlockException; |
| 7 | +import lombok.extern.slf4j.Slf4j; |
3 | 8 | import org.apache.http.HttpResponse; |
4 | 9 | import org.apache.http.client.HttpClient; |
5 | 10 | import org.apache.http.client.config.RequestConfig; |
|
21 | 26 | import java.util.concurrent.ThreadLocalRandom; |
22 | 27 | import java.util.concurrent.TimeUnit; |
23 | 28 |
|
| 29 | +@Slf4j |
24 | 30 | @RestController |
25 | 31 | class CController { |
26 | 32 |
|
@@ -90,9 +96,19 @@ public String spring_boot(HttpServletRequest request) { |
90 | 96 |
|
91 | 97 | @GetMapping("/flow") |
92 | 98 | public String flow(HttpServletRequest request) throws ExecutionException, InterruptedException { |
93 | | - long sleepTime = 5 + RANDOM.nextInt(5); |
94 | | - silentSleep(sleepTime); |
95 | | - return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime; |
| 99 | + try (Entry entry1 = SphU.entry("HelloWorld-c-flow-1", EntryType.IN)) { |
| 100 | + log.debug("Hello Sentinel!1"); |
| 101 | + try (Entry entry2 = SphU.entry("H\"elloWorld-c-flow-2", EntryType.IN)) { |
| 102 | + log.debug("Hello Sentinel!2"); |
| 103 | + long sleepTime = 5 + RANDOM.nextInt(5); |
| 104 | + silentSleep(sleepTime); |
| 105 | + return "C" + serviceTag + "[" + inetUtils.findFirstNonLoopbackAddress().getHostAddress() + "]" + " sleepTime:" + sleepTime; |
| 106 | + } catch (BlockException e) { |
| 107 | + throw new RuntimeException(e); |
| 108 | + } |
| 109 | + } catch (BlockException e) { |
| 110 | + throw new RuntimeException(e); |
| 111 | + } |
96 | 112 | } |
97 | 113 |
|
98 | 114 | @GetMapping("/params/{hot}") |
|
0 commit comments