FallbackHeaders
GatewayFilter
Factory
FallbackHeaders
工厂允许你向在外部应用程序中转发至 fallbackUri
的请求的头中添加 Spring Cloud CircuitBreaker 执行异常详细信息,如下面的场景所示:
The FallbackHeaders
factory lets you add Spring Cloud CircuitBreaker execution exception details in the headers of a request forwarded to a fallbackUri
in an external application, as in the following scenario:
spring:
cloud:
gateway:
routes:
- id: ingredients
uri: lb://ingredients
predicates:
- Path=//ingredients/**
filters:
- name: CircuitBreaker
args:
name: fetchIngredients
fallbackUri: forward:/fallback
- id: ingredients-fallback
uri: http://localhost:9994
predicates:
- Path=/fallback
filters:
- name: FallbackHeaders
args:
executionExceptionTypeHeaderName: Test-Header
在此示例中,在运行断路器时出现执行异常后,请求将转发到运行在 localhost:9994
上的应用程序中的 fallback
端点或处理程序。FallbackHeaders
筛选器会将包含异常类型、消息和(如果可用)根异常类型和消息的头添加到该请求中。
In this example, after an execution exception occurs while running the circuit breaker, the request is forwarded to the fallback
endpoint or handler in an application running on localhost:9994
.
The headers with the exception type, message and (if available) root cause exception type and message are added to that request by the FallbackHeaders
filter.
你可以通过设置以下参数的值(及其默认值)来覆盖配置中的头名称:
You can overwrite the names of the headers in the configuration by setting the values of the following arguments (shown with their default values):
-
executionExceptionTypeHeaderName
("Execution-Exception-Type"
) -
executionExceptionMessageHeaderName
("Execution-Exception-Message"
) -
rootCauseExceptionTypeHeaderName
("Root-Cause-Exception-Type"
) -
rootCauseExceptionMessageHeaderName
("Root-Cause-Exception-Message"
)
有关断路器和网关的更多信息,请参阅 Spring Cloud CircuitBreaker Factory section。
For more information on circuit breakers and the gateway see the Spring Cloud CircuitBreaker Factory section.