Configure automatic retry rules

更新时间:
复制 MD 格式

Use retries to prevent a complete system failure when your system encounters transient failures, such as an occasional timeout exception. The AHAS automatic retry rule feature enables automatic client-side retries and lets you customize the retry strategy. This topic describes how to configure these rules.

Prerequisites

Your application must be connected to Application Guard. For more information, see Connect an application.

Background information

Automatic retry rules are supported only for applications that use AHAS Sentinel Java SDK 1.8.0 or later. This feature is limited to resources that are instrumented with the @SentinelResource annotation or a custom SentinelWrapper, and to applications integrated through the Apache HttpClient and OkHttp adapters. This feature is not available for applications that use the Java Agent or SDKs for other languages. For instructions on how to integrate with an HTTP client, see Integrate an HTTP client.

Usage notes

Avoid configuring an automatic retry rule in the following scenarios:

  • Avoid retrying on a fatal error. Use the exception whitelist mode for your retry condition policy to retry only on specific exceptions such as a timeout exception or a throttling exception. Do not retry on critical errors such as Error, ClassNotFoundException, or IllegalArgumentException. We also advise against retrying on business-logic errors.
  • Ensure idempotency before enabling retries. Retrying a non-idempotent operation can lead to unexpected behavior, especially in scenarios like a timeout where the initial request might have already reached the remote endpoint.
  • Avoid enabling retries for front-end applications that call slow APIs with long timeout periods.
  • In NIO, Netty, or reactive programming scenarios, do not retry within the EventLoop thread. Waiting in this thread can block event propagation and reduce overall system throughput.

Create an automatic retry rule

  1. Log on to the AHAS console, and then select a region in the upper-left corner.
  2. In the left-side navigation pane, choose Traffic Protection > Application Guard.
  3. On the Application Guard page, click the application card for your target application.
  4. In the left-side navigation pane, choose Rule Management. On the Default Plan page, click the Automatic Retry Rules tab.
  5. Click New Automatic Retry Rule.
  6. In the dialog box that appears, configure the following parameters and then click Create.
    ParameterDescription
    Resource nameThe name of the resource to which this rule applies. This name must match the resource name on the monitoring page, which is the name passed during code instrumentation.
    Retry strategyFixed Interval RetryExponential backoffThe strategy for the time interval between retries. The following strategies are supported:
    • Fixed Interval RetryBase retry interval: The time interval between retries is constant and equal to the specified .
    • Exponential Backoff: The retry interval increases exponentially with each attempt, starting from the specified base retry interval. The interval is calculated as base × (factor^n), where the default factor is 1.5. For example, if the base interval is 1,000 ms, subsequent retries occur at 1,500 ms, 2,250 ms, 3,375 ms, and so on.
    Base retry intervalThe base duration for retry attempts. The wait time for each retry is calculated based on this duration and the selected retry strategy. Valid values: 1 ms to 10,000 ms. We recommend setting this to 5,000 ms or less.
    Maximum retriesThe maximum number of retry attempts. We recommend setting this to 3 or less. Valid values: 1 to 10.
    Retry condition policySpecifies the exception conditions that trigger retries.
    • Exception Whitelist Mode: A retry is triggered only if the thrown exception is in the whitelist.
    • Exception Blacklist Mode: A retry is not triggered if the thrown exception is in the blacklist. All other exceptions trigger a retry.
    Whitelist exceptionsA list of exception classes. Provide the fully qualified name for each exception, such as java.lang.IllegalArgumentException. The system performs an exact match on these names.
    Blacklist exceptions
    The newly created rule appears on the Automatic Retry Rules tab.