|
|
@@ -0,0 +1,26 @@
|
|
|
+package anyi.space.memberServer.components;
|
|
|
+
|
|
|
+import com.alibaba.csp.sentinel.slots.block.BlockException;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ProjectName: distributedSystemLearn
|
|
|
+ * @FileName: MySentinelBlockHandler
|
|
|
+ * @Author: 杨逸
|
|
|
+ * @Data:2025/9/19 15:54
|
|
|
+ * @Description: 自定义全局Sentinel的降级处理
|
|
|
+ */
|
|
|
+public class MySentinelBlockHandler {
|
|
|
+ /**
|
|
|
+ * 自定义限流处理
|
|
|
+ * 必须是静态方法,返回值与@SentinelResource注解的标识方法的返回值保持一致
|
|
|
+ * 参数列表与@SentinelResource注解标识方法的参数列表保持一致,可以多一个BlockException参数
|
|
|
+ * @param e
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String myBlockHandler(BlockException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ String msg = "自定义的Sentinel全局myBlockHandler被触发";
|
|
|
+ System.out.println(msg);
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+}
|