Browse Source

Add additional Hystrix documentation. Covers part of #288, fixes #291

pull/305/head
Fitzgerald, Andrew 7 years ago
parent
commit
69bccac870
  1. 12
      docs/src/main/asciidoc/spring-cloud-gateway.adoc
  2. 1
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java
  3. 3
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java

12
docs/src/main/asciidoc/spring-cloud-gateway.adoc

@ -355,6 +355,11 @@ spring: @@ -355,6 +355,11 @@ spring:
This will add `X-Response-Foo:Bar` header to the downstream response's headers for all matching requests.
=== Hystrix GatewayFilter Factory
https://github.com/Netflix/Hystrix[Hystrix] is a library from Netflix that implements the https://martinfowler.com/bliki/CircuitBreaker.html[circuit breaker pattern].
The Hystrix GatewayFilter allows you to introduce circuit breakers to your gateway routes, protecting your services from cascading failures and allowing you to provide fallback responses in the event of downstream failures.
To enable Hystrix GatewayFilters in your project, add a dependency on `spring-cloud-starter-netflix-hystrix` from http://cloud.spring.io/spring-cloud-netflix/[Spring Cloud Netflix].
The Hystrix GatewayFilter Factory requires a single `name` parameter, which is the name of the `HystrixCommand`.
.application.yml
@ -395,6 +400,13 @@ spring: @@ -395,6 +400,13 @@ spring:
----
This will forward to the `/incaseoffailureusethis` URI when the Hystrix fallback is called. Note that this example also demonstrates (optional) Spring Cloud Netflix Ribbon load-balancing via the `lb` prefix on the destination URI.
Hystrix settings (such as timeouts) can be configured with global defaults or on a route by route basis using application properties as explained on the https://github.com/Netflix/Hystrix/wiki/Configuration[Hystrix wiki].
To set a 5 second timeout for the example route above, the following configuration would be used:
.application.yml
[source,yaml]
hystrix.command.fallbackcmd.execution.isolation.thread.timeoutInMilliseconds: 5000
=== PrefixPath GatewayFilter Factory
The PrefixPath GatewayFilter Factory takes a single `prefix` parameter.

1
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/HystrixGatewayFilterFactory.java

@ -50,6 +50,7 @@ import rx.RxReactiveStreams; @@ -50,6 +50,7 @@ import rx.RxReactiveStreams;
import rx.Subscription;
/**
* Depends on `spring-cloud-starter-netflix-hystrix`, {@see http://cloud.spring.io/spring-cloud-netflix/}
* @author Spencer Gibb
*/
public class HystrixGatewayFilterFactory extends AbstractGatewayFilterFactory<HystrixGatewayFilterFactory.Config> {

3
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/route/builder/GatewayFilterSpec.java

@ -113,6 +113,9 @@ public class GatewayFilterSpec extends UriSpec { @@ -113,6 +113,9 @@ public class GatewayFilterSpec extends UriSpec {
.apply(c -> c.setName(headerName).setValue(headerValue)));
}
/**
* Depends on `spring-cloud-starter-netflix-hystrix`, {@see http://cloud.spring.io/spring-cloud-netflix/}
*/
public GatewayFilterSpec hystrix(Consumer<HystrixGatewayFilterFactory.Config> configConsumer) {
HystrixGatewayFilterFactory factory;
try {

Loading…
Cancel
Save