Sfoglia il codice sorgente

gateway网关:熔断器拦截优化

ZhangWenQiang 5 anni fa
parent
commit
9306ff1c25

+ 24 - 0
happy-cloud-gateway/src/main/java/org/jeecg/fallback/FallbackController.java

@@ -0,0 +1,24 @@
+package org.jeecg.fallback;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Mono;
+
+/**
+ * @Author: zwq
+ * @Date: Create in 2021/1/12 9:57
+ * @Description: 响应超时熔断处理器
+ */
+@RestController
+public class FallbackController {
+
+    /**
+     * 全局熔断处理
+     *
+     * @return
+     */
+    @RequestMapping("/fallback")
+    public Mono<String> fallback() {
+        return Mono.just("访问超时,请稍后再试!");
+    }
+}

+ 1 - 1
happy-cloud-gateway/src/main/java/org/jeecg/handler/HystrixFallbackHandler.java

@@ -29,6 +29,6 @@ public class HystrixFallbackHandler implements HandlerFunction<ServerResponse> {
 		originalUris.ifPresent(originalUri -> log.error("网关执行请求:{}失败,hystrix服务降级处理", originalUri));
 
 		return ServerResponse.status(HttpStatus.INTERNAL_SERVER_ERROR.value())
-			.header("Content-Type","text/plain; charset=utf-8").body(BodyInserters.fromObject("服务异常"));
+			.header("Content-Type","text/plain; charset=utf-8").body(BodyInserters.fromObject("访问超时,请稍后再试"));
 	}
 }

+ 4 - 1
happy-cloud-gateway/src/main/java/org/jeecg/handler/MySwaggerResourceProvider.java

@@ -54,7 +54,10 @@ public class MySwaggerResourceProvider implements SwaggerResourcesProvider {
                 SwaggerResource swaggerResource = new SwaggerResource();
                 swaggerResource.setUrl(url);
                 swaggerResource.setName(instance);
-                resources.add(swaggerResource);
+                //Swagger排除监控模块
+                if(instance.indexOf("happy-cloud-monitor")==-1){
+                    resources.add(swaggerResource);
+                }
             }
         });
         return resources;