All Products
Search
Document Center

Microservices Engine:Configure behaviors

Last Updated:Apr 01, 2025

Fallback behaviors are triggered for web resources and RPC resources when the preset throttling threshold is reached, circuit breaking is triggered, or degradation is performed based on rules. If a fallback behavior is triggered for web resources, a standby controller or processor is configured to return user-friendly prompts, or other alternative operations are performed. The fallback behavior does not directly return an exception or an error code. If a fallback behavior is triggered for RPC resources, the local fallback method instead of a remote service is called. This prevents call process interruptions due to the unavailability of the remote service.

Prerequisites

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 destination application. In the left-side navigation pane, click Traffic management.

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

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

    Web resources

    Parameter

    Description

    Example

    Behavior Name

    The name of the behavior. The name length cannot exceed 128 characters. The name must be unique in an application.

    Test behavior

    Resource Type

    Select Web for this parameter.

    Web

    Web Throttling Policy

    The behavior that is to be performed after a web interface triggers a specific rule. By default, Custom return is selected. You need to further customize the HTTP response status code and the format and content of the HTTP response. After a web interface triggers a specific rule, the custom content is returned.

    Custom return

    HTTP Status Code

    The default value is 429. You must configure this parameter if the Web flow limiting processing strategy parameter is set to Custom return.

    429

    Returned Content-Type

    The format of the HTTP response. Valid values: Plain text and JSON.

    JSON

    Returned HTTP Text

    The content of the HTTP response to be returned after a web interface triggers a specific rule. You must configure this parameter if the Web flow limiting processing strategy parameter is set to Custom return.

    {"message": "blocked oops"}

    RPC resources

    Parameter

    Description

    Example

    Behavior Name

    The name of the behavior. The name length cannot exceed 128 characters. The name must be unique in an application.

    Test behavior

    Resource Type

    Select Rpc for this parameter.

    Note

    Apache Dubbo versions 2.7.0 to 2.7.3 do not support custom behaviors. The java.lang.RuntimeException error message is returned when throttling is triggered in the preceding versions. The error message contains SentinelBlockedException and throttling information.

    Rpc

    Rpc current limiting processing strategy

    The behavior that is to be performed after an RPC interface triggers a specific rule.

    • Custom return: the custom response. You need to customize the HTTP response status code and the format and content of the HTTP response. After an RPC interface triggers a specific rule, the custom content is returned.

    • Custom exception: the custom exception that is returned. You need to specify the Exception Class Name and Exception Message Text parameters. After an RPC interface triggers a specific rule, the custom exception is returned.

    Custom return or Custom exception

    Rpc current limiting processing strategy set to Custom return

    Custom Response Class Name

    The path of the class name.

    Note

    The custom response does not support generic types that contain unknown types, such as Map<K, V> and List<T>.

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

    Custom Response Content (JSON Format)

    The custom content that is returned after an RPC interface triggers a specific rule.

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

    Rpc current limiting processing strategy set to Custom exception

    Exception Class Name

    The path of the exception class name.

    java.lang.RuntimeException

    Exception Message Text

    The custom exception text that is returned after an RPC interface triggers a specific rule.

    "Operation failed"

    The created behavior is displayed on the Behavior Management tab.

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 destination application. In the left-side navigation pane, click Traffic management.

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

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

Associate a behavior with a rule

You can associate different behaviors with different rules. In this topic, a behavior is associated with a throttling rule.

  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 destination application. In the left-side navigation pane, click Traffic management.

  4. On the Traffic management page, click the Flow protection tab and then 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, configure the parameters. Select Protection ScenarioConfigure Protection Rule

    1. In the Select Protection Scenario step, set API Type to WEB service or RPC service, and configure the Type of traffic, Interface name, and Protection Type parameters.

    2. In the Configure Protection Rule step, configure the Stand-alone QPS threshold and Flow control effect parameters.

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

    Note
    • If you do not need to customize the fallback behavior that is to be performed after throttling, select Default Behavior and leave the API Type parameter unspecified by default.

    • When you add a rule, if the current interface is already associated with a behavior, the behavior is overwritten by the new behavior that you associate with the interface.

    • If you do not specify the API Type parameter in the Select Protection Scenario step, the default behavior is associated. After you specify the API Type parameter and associate a behavior of the specified type, you can change the behavior but not the behavior type.

    • The fallback mechanism of the Feign framework takes effect. Custom behaviors that are configured in the MSE console do not take effect.

  7. Click New.