Configure fallback behaviors

更新时间:
复制 MD 格式

A fallback behavior provides alternative logic that is activated when a monitored Web resource or RPC resource triggers a flow control, circuit breaking, or degradation rule. For a Web resource, you can configure a fallback controller or handler to return a user-friendly message or perform another action, instead of throwing an exception or returning an error status code. For an RPC resource, the fallback behavior calls a local fallback method in place of a remote service call, preventing the entire call chain from being interrupted if the remote service is unavailable.

Prerequisites

Before you begin, make sure you have:

Create a behavior

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance.

  3. On the Application list page, click the resource card of the desired application. In the left-side navigation pane, click Traffic management.

  4. On the Traffic management page, click the Flow protection tab, and then click the Behavior Management tab.

  5. Click New behavior. In the New behavior dialog box, select a resource type, complete the configuration, and then click New.

    Web resource

    Parameter

    Description

    Example

    Behavior Name

    A unique name for the behavior within the application, up to 128 characters long.

    Test behavior

    Resource Type

    Select Web.

    Web

    Web Throttling Policy

    Specifies the action to take when a rule is triggered for a Web interface. If you select Custom return, you must specify the HTTP status code, content format, and response body to return custom content.

    Custom return

    HTTP Status Code

    The default value is 429. This parameter is required when Web Throttling Policy is set to Custom return.

    429

    Returned Content-Type

    The format of the response body. You can select Plain text or JSON.

    JSON

    Returned HTTP Text

    The content of the response body returned when the rule is triggered. This parameter is required when Web Throttling Policy is set to Custom return.

    {"message": "blocked oops"}

    RPC resource

    Parameter

    Description

    Example

    Behavior Name

    A unique name for the behavior within the application, up to 128 characters long.

    Test behavior

    Resource Type

    Select RPC.

    Note

    Apache Dubbo 2.7.0 to 2.7.3 does not support custom behaviors. In these versions, throttling returns a java.lang.RuntimeException that includes SentinelBlockedException and throttling details.

    RPC

    Rpc current limiting processing strategy

    Specifies the action to take when a rule is triggered for an RPC interface.

    • Custom return: Returns a custom result. You must configure the response class and content.

    • Custom exception: Throws a custom exception. You must configure the exception class name and message.

    Custom return/Custom exception

    Rpc current limiting processing strategy is set to Custom return

    Custom Response Class Name

    Enter the fully qualified class name.

    Note

    Custom return does not currently support object types with unresolved generic parameters, such as Map<K, V> and List<T>.

    com.alibaba.demo.OrderService:getOrder(long)

    Custom Response Content (JSON Format)

    The content of the object to return when the rule is triggered for the RPC interface.

    {"id": "123", "name": "test"}

    Rpc current limiting processing strategy is set to Custom exception

    Exception Class Name

    Enter the fully qualified exception class name.

    java.lang.RuntimeException

    Exception Message Text

    Enter the message for the custom exception that is thrown when a rule is triggered for the RPC interface.

    "Operation failed"

    The new behavior appears on the Behavior Management page.

Modify or delete a behavior

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance.

  3. On the Application list page, click the resource card of the desired application. In the left-side navigation pane, click Traffic management.

  4. On the Traffic management page, click the Flow protection tab, and then click the Behavior Management tab.

  5. Find the target behavior and click Revised or Delete in the Actions column.

Associate a behavior with a rule

You can associate different fallback behaviors with different control rules. This section uses a throttling rule as an example.

  1. Log on to the MSE console, and select a region in the top navigation bar.

  2. In the left-side navigation pane, choose Microservices Governance > Application Governance.

  3. On the Application list page, click the resource card of the desired application. In the left-side navigation pane, click Traffic management.

  4. On the Traffic management page, click the Flow protection tab, and then click the Interface Flow Control tab.

  5. On the Interface Flow Control tab, click Add Throttling Rule.

  6. In the Add Throttling Protection Rule dialog box, complete the configuration. After you complete the Select Protection Scenario and Configure Protection Rule steps, configure the following parameters in the Configure Protection Behavior area.

    1. In the Select Protection Scenario step, select API Type as WEB service or RPC service, and then select Type of traffic, Interface Name, and Protection Type.

    2. In the Configure Protection Rule step, set the Stand-alone QPS threshold and select a Flow control effect.

    3. In the Configure Protection Behavior step, select a target behavior from the Association Behavior drop-down list, or click New behavior to create a new one.

    Note
    • To use the default fallback behavior for throttling, do not specify an API type.

    • Associating a behavior with a rule overwrites any previously associated behavior.

    • If you do not select an API type, the default behavior is used. After you associate a behavior of a specific API type, you can modify the behavior, but you cannot change its type.

    • Custom behaviors configured in Microservices Governance do not affect the Feign framework, as its native fallback mechanism takes precedence.

  7. Click New.