Connect a Dubbo application

更新时间:
复制 MD 格式

After connecting your Dubbo application to AHAS Application Protection, you can configure flow control, degradation, and system rules to ensure its stability. This topic describes how to connect a Dubbo application using an SDK.

Procedure

  1. Log on to the AHAS console.

  2. In the upper-left corner of the AHAS console, select the region where you want to connect your application.

  3. In the left-side navigation pane, choose Traffic Protection > Application Protection.

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

  5. On the JAVA tab, click SDK Access, and then click Dubbo/HFS Application Access.

  6. Add the dependency for AHAS Application Protection to your Dubbo application by using one of the following methods:

    • Add the following dependency to the pom.xml file of your Dubbo application. (SDK/Starter versions 1.8.6 and later support mainstream versions of Dubbo 2.6.x and 2.7.x.)

      <dependency>
        <groupId>com.alibaba.csp</groupId>
        <artifactId>ahas-sentinel-client</artifactId>
        <!-- You can specify a version number. For the latest version, see the New Application Integration page in the AHAS console. -->
        <version>x.y.z</version>
      </dependency>

      On the Dubbo Application Access page, view the latest version of the POM dependency and replace x.y.z with the latest version number.

      Dubbo版本号2.png

      Note

      If your Dubbo service is a Spring Boot application, you can connect it using the Spring Boot method. For more information, see Connect a Spring Boot/Spring Cloud application.

    • Add JAR package dependencies.

      On the Dubbo Application Access page, click Click this link to download to download the compressed package, and then place all JAR files from the package into your classpath directory.

  7. Configure the startup parameters for your application.

    Category

    Configuration example

    Internal network

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

    • Replace <RegionId> with the ID of the region where your application is deployed. For the mapping between regions and RegionIds, see the Region and RegionId mapping table section below.

    Public network

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

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

    If you are in a public network region, you must view the License information. You can find this information in the Step 2: Add Instrumentation area (this is not required for internal network regions). For more information, see View License.

    dubbo license2.png

  8. Restart your application.

  9. Optional: You can customize the fallback logic for throttling, degradation, or system protection rules. To do this, implement the DubboFallback interface and register it with DubboFallbackRegistry. With this configuration, AHAS wraps and throws a BlockException when a flow control, degradation, or system rule triggers. For more information, see Dubbo Adapter.

    Note

    If you skip this step, the system throws a subclass of the BlockException by default when an Application Protection rule triggers. For example, a FlowException is thrown for a flow control rule, and a DegradeException is thrown for a degradation rule.

Verify the results

Log on to the AHAS console. In the left-side navigation pane, choose Traffic Protection > Application Protection. If a resource card for your application appears on the Application Protection page and data reporting is active, the connection is successful.

应用防护.png

Region and RegionId mapping table

Region

RegionId

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