FallbackHeaders GatewayFilter 工廠

FallbackHeaders 工廠允許您將 Spring Cloud CircuitBreaker 執行異常詳細資訊新增到轉發到外部應用程式中 fallbackUri 的請求頭中,如下所示:

application.yml
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: https://:9994
        predicates:
        - Path=/fallback
        filters:
        - name: FallbackHeaders
          args:
            executionExceptionTypeHeaderName: Test-Header

在此示例中,當執行熔斷器時發生執行異常後,請求將被轉發到執行在 localhost:9994 的應用程式中的 fallback 端點或處理程式。FallbackHeaders 過濾器將包含異常型別、訊息以及(如果可用)根原因異常型別和訊息的請求頭新增到該請求中。

您可以透過設定以下引數的值(顯示預設值)來覆蓋配置中請求頭的名稱:

  • executionExceptionTypeHeaderName ("Execution-Exception-Type")

  • executionExceptionMessageHeaderName ("Execution-Exception-Message")

  • rootCauseExceptionTypeHeaderName ("Root-Cause-Exception-Type")

  • rootCauseExceptionMessageHeaderName ("Root-Cause-Exception-Message")

有關熔斷器和閘道器的更多資訊,請參閱 Spring Cloud CircuitBreaker Factory 部分

© . This site is unofficial and not affiliated with VMware.