Integrate a Spring Cloud Gateway application

更新时间:
复制 MD 格式

Integrate Spring Cloud Gateway applications with AHAS Gateway Protection by using an SDK. This integration allows you to configure flow control rules to ensure system stability.

Procedure

  1. Log on to the AHAS console and select a region in the upper-left corner of the page.

  2. In the left-side navigation pane, choose Application Protection > Gateway Protection.

  3. In the upper-right corner of the Gateway Protection page, click Add Gateway. Then, click the Spring Cloud Gateway tab.

  4. Add the following dependency to your Spring Cloud Gateway application's pom.xml file:

    <dependency>
     <groupId>com.alibaba.csp</groupId>
     <artifactId>spring-cloud-gateway-starter-ahas-sentinel</artifactId>
     <version>x.y.z</version>
    </dependency>

    Replace x.y.z with the latest version number, which is displayed on the Spring Cloud Gateway tab.

    SpringCloud.png

  5. Configure the startup parameters for your application using one of the following methods.

    • Add JVM -D parameters.

      • For environments not on the public network, add the following parameter:

        // Replace AppName with a custom application name.
        -Dproject.name=AppName
      • For environments on the public network, add the following parameters:

        // Replace AppName with a custom application name and <license> with your license key.
        -Dproject.name=AppName 
        -Dahas.license=<license>
    • Add the following configuration to the application.properties file:

      • For environments not on the public network, add the following parameters:

        # Specify the AHAS environment to connect to.
        ahas.namespace=default
        # Specify a custom name for your application.
        project.name=AppName
      • For environments on the public network, add the following parameters:

        # Specify the AHAS environment to connect to.
        ahas.namespace=default
        # Specify a custom name for your application.
        project.name=AppName
        # Configure your license key.
        ahas.license=<license>

    Connecting to AHAS over the public network requires a license key. You can find the key in the Step 2: Configure the startup parameters section. For more information, see View License.

    SpringCloud网关 license.png

  6. Restart the gateway application.

Verify the result

To verify the integration, log on to the AHAS console and go to Application Protection > Gateway Protection. The integration is successful if a resource card for the gateway application appears on the Gateway Protection page.

网关防护.png

Next steps

After integrating the gateway application, you can configure gateway flow control rules.