You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/main/asciidoc/spring-cloud-gateway.adoc
+96-4Lines changed: 96 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -465,6 +465,11 @@ The DedupeResponseHeader filter also accepts an optional `strategy` parameter. T
465
465
466
466
[[hystrix]]
467
467
=== Hystrix GatewayFilter Factory
468
+
469
+
NOTE: https://cloud.spring.io/spring-cloud-netflix/multi/multi__modules_in_maintenance_mode.html[Netflix has put Hystrix in maintenance mode]. It is suggested you use the <<spring-cloud-circuitbreaker-filter-factory, Spring Cloud CircuitBreaker
470
+
Gateway Filter>> with Resilience4J as support for Hystrix will be removed in a future release.
471
+
472
+
468
473
https://github.com/Netflix/Hystrix[Hystrix] is a library from Netflix that implements the https://martinfowler.com/bliki/CircuitBreaker.html[circuit breaker pattern].
469
474
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.
470
475
@@ -554,10 +559,96 @@ To set a 5 second timeout for the example route above, the following configurati
The Spring Cloud CircuitBreaker filter can also accept an optional `fallbackUri` parameter. Currently, only `forward:` schemed URIs are supported. If the fallback is called, the request will be forwarded to the controller matched by the URI.
This will forward to the `/incaseoffailureusethis` URI when the circuit breaker fallback is called. Note that this example also demonstrates (optional) Spring Cloud Netflix Ribbon load-balancing via the `lb` prefix on the destination URI.
611
+
612
+
The primary scenario is to use the `fallbackUri` to an internal controller or handler within the gateway app.
613
+
However, it is also possible to reroute the request to a controller or handler in an external application, like so:
614
+
615
+
.application.yml
616
+
[source,yaml]
617
+
----
618
+
spring:
619
+
cloud:
620
+
gateway:
621
+
routes:
622
+
- id: ingredients
623
+
uri: lb://ingredients
624
+
predicates:
625
+
- Path=//ingredients/**
626
+
filters:
627
+
- name: CircuitBreaker
628
+
args:
629
+
name: fetchIngredients
630
+
fallbackUri: forward:/fallback
631
+
- id: ingredients-fallback
632
+
uri: http://localhost:9994
633
+
predicates:
634
+
- Path=/fallback
635
+
----
636
+
637
+
In this example, there is no `fallback` endpoint or handler in the gateway application, however, there is one in another
638
+
app, registered under `http://localhost:9994`.
639
+
640
+
In case of the request being forwarded to fallback, the Spring Cloud CircuitBreaker Gateway filter also provides the `Throwable` that has
641
+
caused it. It's added to the `ServerWebExchange` as the
642
+
`ServerWebExchangeUtils.CIRCUITBREAKER_EXECUTION_EXCEPTION_ATTR` attribute that can be used when
643
+
handling the fallback within the gateway app.
644
+
645
+
For the external controller/handler scenario, headers can be added with exception details. You can find more information
646
+
on it in the <<fallback-headers, FallbackHeaders GatewayFilter Factory section>>.
647
+
557
648
[[fallback-headers]]
558
649
=== FallbackHeaders GatewayFilter Factory
559
650
560
-
The `FallbackHeaders` factory allows you to add Hystrix execution exception details in headers of a request forwarded to
651
+
The `FallbackHeaders` factory allows you to add Hystrix or Spring Cloud CircuitBreaker execution exception details in headers of a request forwarded to
561
652
a `fallbackUri` in an external application, like in the following scenario:
562
653
563
654
.application.yml
@@ -572,7 +663,7 @@ spring:
572
663
predicates:
573
664
- Path=//ingredients/**
574
665
filters:
575
-
- name: Hystrix
666
+
- name: CircuitBreaker
576
667
args:
577
668
name: fetchIngredients
578
669
fallbackUri: forward:/fallback
@@ -586,7 +677,7 @@ spring:
586
677
executionExceptionTypeHeaderName: Test-Header
587
678
----
588
679
589
-
In this example, after an execution exception occurs while running the `HystrixCommand`, the request will be forwarded to
680
+
In this example, after an execution exception occurs while running the circuit breaker, the request will be forwarded to
590
681
the `fallback` endpoint or handler in an app running on `localhost:9994`. The headers with the exception type, message
591
682
and -if available- root cause exception type and message will be added to that request by the `FallbackHeaders` filter.
You can find more information on how Hystrix works with Gateway in the <<hystrix, Hystrix GatewayFilter Factory section>>.
692
+
For more information of circuit beakers and the Gateway see the <<hystrix, Hystrix GatewayFilter Factory section>> or
693
+
<<spring-cloud-circuitbreaker-filter-factory, Spring Cloud CircuitBreaker Factory section>>.
602
694
603
695
=== MapRequestHeader GatewayFilter Factory
604
696
The MapRequestHeader GatewayFilter Factory takes 'fromHeader' and 'toHeader' parameters. It creates a new named header (toHeader) and the value is extracted out of an existing named header (fromHeader) from the incoming http request. If the input header does not exist then the filter has no impact. If the new named header already exists then it's values will be augmented with the new values.
Copy file name to clipboardExpand all lines: spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -710,6 +710,7 @@ public HystrixGatewayFilterFactory hystrixGatewayFilterFactory(
Copy file name to clipboardExpand all lines: spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/factory/FallbackHeadersGatewayFilterFactory.java
0 commit comments