Onboard an HSF application

更新时间:
复制 MD 格式

After onboarding a High-speed Service Framework (HSF) application to Application High-Availability Service (AHAS), you can configure traffic control, degradation, and system protection rules to ensure its stability. This guide explains how to integrate an HSF application with Application Protection by using an SDK.

Procedure

  1. Log in to the AHAS console.

  2. In the upper-left corner of the AHAS console, select the region for your application.

  3. In the left-side navigation pane, choose Application High-Availability Service > Application Protection.

  4. In the upper-right corner of the Application Protection page, click New Application.

  5. On the JAVA Language tab, click SDK Onboarding, and then click Dubbo/HSF Application Onboarding.

  6. Add the Application Protection dependency to your HSF application:

    • For Spring Boot applications, add the following starter dependency to your pom.xml file:

      <dependency>
        <groupId>com.alibaba.csp</groupId>
        <artifactId>spring-boot-starter-ahas-sentinel-client</artifactId>
        <!-- You must specify a version. The version must be 1.7.2 or later. For the latest version, see the instructions on the New Application page in the AHAS console. -->
        <version>x.y.z</version>
      </dependency>
    • For other applications, add the following dependency to your pom.xml file:

      <dependency>
        <groupId>com.alibaba.csp</groupId>
        <artifactId>ahas-sentinel-client</artifactId>
        <!-- You must specify a version. The version must be 1.7.2 or later. For the latest version, see the instructions on the New Application page in the AHAS console. -->
        <version>x.y.z</version>
      </dependency>

    On the Dubbo/HSF Application Onboarding page, find the latest dependency version in the Step 1: Add Pom Dependency section. Replace x.y.z with the latest version number.

    HSF接入1.png

  7. Configure the startup parameters for your application.

    Category

    Example

    intranet

    -Dproject.name=AppName -Dahas.namespace=default -Dahas.regionId=<RegionId>
    Note
    • Replace AppName with your application name.

    • Replace <RegionId> with your application's Region ID. For a list of regions and their IDs, see the Region and Region ID section below.

    public network

    -Dproject.name=AppName -Dahas.license=<license> -Dahas.namespace=default -Dahas.regionId=cn-public
    Note

    Replace AppName with your application name and <license> with your license key.

    Applications deployed over the public network require a license key. You can find this key in the Step 2: Add Probe section. This is not required for intranet deployments. For more information, see View License.

    dubbo license2.png

  8. Restart your application.

  9. Optional:To customize the fallback logic for traffic control, degradation, or system protection rule triggers, implement the HsfFallback interface. Register your implementation by using HsfFallbackRegistry (setProviderFallback for service providers and setConsumerFallback for service consumers). Once registered, AHAS passes the BlockException to your custom handler when a rule is triggered.

    Note

    If you do not provide a custom fallback, a RuntimeException("SentinelBlockException") is thrown by default when a rule is triggered for the HSF application.

Verify the results

Log in to the AHAS console. In the left-side navigation pane, choose Application High-Availability Service > Application Protection. The application is successfully onboarded if its resource card appears on the Application Protection page and reports data.

应用防护.png

Region and Region ID

Region

Region ID

public network

cn-public

China (Hangzhou)

cn-hangzhou

China (Shanghai)

cn-shanghai

China (Beijing)

cn-beijing

China (Zhangjiakou)

cn-zhangjiakou

China (Shenzhen)

cn-shenzhen

Singapore

ap-southeast-1

Germany (Frankfurt)

eu-central-1