Integrate a Spring Cloud Zuul application

更新时间:
复制 MD 格式

To protect your Spring Cloud Zuul application, integrate it with AHAS gateway protection using an SDK. This allows you to configure throttling rules to ensure application stability.

Procedure

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

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

  3. On the Gateway Protection page, click Gateway Access in the upper-right corner. Then, select the Zuul (1.x) Gateway Access tab.
  4. In the pom.xml file of your Spring Cloud Zuul application, add the following dependency:
    <dependency>
     <groupId>com.alibaba.csp</groupId>
     <artifactId>spring-cloud-zuul-starter-ahas-sentinel</artifactId>
     <version>x.y.z</version>
    </dependency>
    Note Replace x.y.z with the latest dependency version, which is available on the Zuul (1.x) Gateway Access tab.
    zuul version.png
  5. Configure the startup parameters for the application using one of the following methods.
    • Add JVM -D parameters.
      • For a private network environment, add the following parameter:
        // Replace AppName with your custom application name.
        -Dproject.name=AppName
      • For an Internet-facing environment, add the following parameters:
        // Replace AppName with your custom application name and <license> with your actual license.
        -Dproject.name=AppName 
        -Dahas.license=<license>
    • Modify the Spring properties file. In the application.properties file, add the following parameters:
      • For a private network environment, add the following parameters:
        # Specify the AHAS environment to integrate with.
        ahas.namespace=default
        # Specify your custom application name.
        project.name=AppName
      • For an Internet-facing environment, add the following parameters:
        # Specify the AHAS environment to integrate with.
        ahas.namespace=default
        # Specify your custom application name.
        project.name=AppName
        # Configure the license information.
        ahas.license=<license>

    For deployments in an Internet-facing environment, you must provide a license. You can find your license in the Step 2: Configure startup parameters section. Deployments in private network environments do not require a license. For more information, see View your license.

    zuul license.png
  6. Restart your gateway application.

Verify the integration

Log in to the AHAS console. In the left-side navigation pane, choose Traffic Protection > Gateway Protection. If a resource card for your gateway application appears on the Gateway Protection page, the integration is successful.

网关防护.png

Next steps

After integrating the gateway application, you can configure gateway throttling rules for it.