1919import org .springframework .web .bind .annotation .RestController ;
2020
2121import javax .annotation .PostConstruct ;
22+ import java .io .IOException ;
2223import java .util .Random ;
2324import java .util .concurrent .ExecutionException ;
2425import java .util .concurrent .TimeUnit ;
@@ -65,14 +66,16 @@ public String c() {
6566 throw new RuntimeException ();
6667 }
6768 try (Entry entry1 = SphU .entry ("HelloWorld-c-1" , EntryType .IN )) {
68- log .debug ("Hello Sentinel!1" );
69- try (Entry entry2 = SphU .entry ("H\" elloWorld-c-2" , EntryType .IN )) {
70- log .debug ("Hello Sentinel!2" );
69+ // 具体的业务逻辑
70+ try {
7171 return "C" + serviceTag + "[" + inetUtils .findFirstNonLoopbackAddress ().getHostAddress () + "]" ;
72- } catch (BlockException e ) {
73- throw new RuntimeException (e );
72+ } catch (Throwable e ) {
73+ // 标记此次资源调用失败
74+ entry1 .setError (e );
75+ throw e ;
7476 }
7577 } catch (BlockException e ) {
78+ // 处理限流发生后的逻辑
7679 throw new RuntimeException (e );
7780 }
7881 }
@@ -82,7 +85,17 @@ public String cZone() {
8285 if (throwException ) {
8386 throw new RuntimeException ();
8487 }
85- return "C" + serviceTag + "[" + currentZone + "]" ;
88+ try (Entry entry2 = SphU .entry ("H\" elloWorld-c-2" , EntryType .IN )) {
89+ try {
90+ log .debug ("Hello Sentinel!2" );
91+ return "C" + serviceTag + "[" + currentZone + "]" ;
92+ } catch (Throwable e ) {
93+ entry2 .setError (e );
94+ throw e ;
95+ }
96+ } catch (BlockException e ) {
97+ throw new RuntimeException (e );
98+ }
8699 }
87100
88101 @ GetMapping ("/spring_boot" )
0 commit comments