完善熔断、监控
diff --git a/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/GatewayApplication.java b/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/GatewayApplication.java
index 39b0c99..089a50c 100644
--- a/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/GatewayApplication.java
+++ b/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/GatewayApplication.java
@@ -10,4 +10,17 @@
SpringApplication.run(GatewayApplication.class, args);
}
+//
+// @Bean
+// public ServletRegistrationBean<HystrixMetricsStreamServlet> hystrixMetricsStreamServlet() {
+// HystrixMetricsStreamServlet hystrixMetricsStreamServlet = new HystrixMetricsStreamServlet();
+//
+// ServletRegistrationBean<HystrixMetricsStreamServlet> servletRegistrationBean = new ServletRegistrationBean<HystrixMetricsStreamServlet>(hystrixMetricsStreamServlet);
+// servletRegistrationBean.setName("hystrixMetricsStreamServlet");
+// servletRegistrationBean.setLoadOnStartup(1);
+// servletRegistrationBean.addUrlMappings("/hystrix.stream");
+//
+// return servletRegistrationBean;
+// }
+//
}
diff --git a/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/controller/error/ErrorController.java b/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/controller/error/ErrorController.java
new file mode 100644
index 0000000..77cb767
--- /dev/null
+++ b/samples/gateway/src/main/java/com/supwisdom/leaveschool/gateway/controller/error/ErrorController.java
@@ -0,0 +1,27 @@
+package com.supwisdom.leaveschool.gateway.controller.error;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
+import org.springframework.util.MimeTypeUtils;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class ErrorController {
+
+ private static final Logger logger = LoggerFactory.getLogger(ErrorController.class);
+
+ @RequestMapping(value = "/error", produces = MimeTypeUtils.APPLICATION_JSON_VALUE)
+ @ResponseStatus(value = HttpStatus.BAD_GATEWAY)
+ public Map<String, Object> error() {
+ logger.debug("error");
+ Map<String, Object> result = new HashMap<String, Object>();
+ result.put("error", "Bad Gateway");
+ return result;
+ }
+}
diff --git a/samples/gateway/src/main/resources/application.yml b/samples/gateway/src/main/resources/application.yml
index f472001..35065a6 100755
--- a/samples/gateway/src/main/resources/application.yml
+++ b/samples/gateway/src/main/resources/application.yml
@@ -6,7 +6,7 @@
level:
root: INFO
org.springframework.web: INFO
- org.springframework.cloud.gateway: INFO
+ org.springframework.cloud.gateway: TRACE
com.supwisdom.infras.security: DEBUG
com.supwisdom.leaveschool: DEBUG
@@ -23,5 +23,21 @@
- Path=/api/sample-user/**
filters:
- RewritePath=/(?<prefix>.*)/sample-user/(?<suffix>.*), /$\{prefix}/$\{suffix}
+ - name: Hystrix
+ args:
+ name: default
+ fallbackUri: forward:/error
+ metrics:
+ enabled: true
+
+hystrix:
+ command:
+ default:
+ execution:
+ timeout:
+ enabled: true
+ isolation:
+ thread:
+ timeoutInMilliseconds: 5000
management.endpoints.web.exposure.include: '*'