All Products
Search
Document Center

Enterprise Distributed Application Service:Configure tag-based routing for Spring Cloud applications

Last Updated:Oct 23, 2023

The tag-based routing feature allows you to allocate one or more application instances to the same group by using tags. This way, you can forward traffic to application instances in specific groups. The tag-based routing feature can be used in scenarios such as multi-version development and testing, traffic adjustment for a multi-version application, and A/B testing. This topic describes how to configure tag-based routing for Spring Cloud applications.

Background information

The tag-based routing feature is available only for applications that are deployed in Elastic Compute Service (ECS) clusters.

Scenarios

Multi-version development and testing

If multiple versions are developed at the same time, you must prepare a development environment for each version. The costs of development environments are high. To reduce costs, you can use tag-based routing to implement end-to-end traffic adjustment.

End-to-end traffic adjustment is implemented based on the tag-based routing feature. End-to-end traffic adjustment allows you to route specific traffic to a specific development environment. For example, in Development Environment 1, create Tag 1 for Application B (V1.1) and Application D (V1.1), and configure a tag-based routing rule. This way, when Application A calls Application B, the system checks whether the traffic meets the conditions of the tag-based routing rule. If yes, the traffic is routed to Application B (V1.1) in Development Environment 1. If no, the traffic is routed to Application B (V1) in the baseline environment. When Application C calls Application D, the traffic is routed to Application D (V1) or Application D (V1.1) based on the tag-based routing rule.

Traffic adjustment for a multi-version application

If multiple versions of an application run online at the same time and are deployed in different environments, such as the common environment and special environment, you can use the tag-based routing feature to isolate the traffic that is destined for different versions in different environments. For example, you can route the traffic of flash sales orders or the traffic of orders from different channels to the special environment, and route common traffic to the common environment. This way, the traffic that is destined for the special environment is not routed to the common environment even if exceptions occur in the special environment, and the common environment is not affected.

A/B Testing

Multiple versions of an application run online at the same time. To perform A/B testing on the different versions of the application, you can use end-to-end traffic adjustment to route the traffic that is initiated from Region A to Application V1, and route the traffic that is initiated from Region B to Application V1.1. Then, you can verify the different versions. This helps reduce risks when you release new products or features and facilitates product innovation.

Procedure

In this example, Application A is deployed in an ECS cluster. Application A has a default group, and the group contains three application instances.

Perform the following steps to configure tag-based routing:

  1. Create a tag:

    1. Create Group 1 and Group 2 for Application A.

    2. Allocate one application instance in the default group to Group 1 and another application instance in the default group to Group 2.

    3. Create tags for Group 1 and Group 2.

  2. Create a tag-based routing rule: Create tag-based routing rules based on the tags of Group 1 and Group 2.

After the tag-based routing rules are created, when Application B calls Application A, traffic is routed to Group 1 and Group 2 based on the rules. Other traffic that does not meet the conditions of the tag-based routing rules for Group 1 and Group 2 is routed to the default group.

Create a tag

Create a group for an application and add an instance to the group. Then, select JVM from the Group Settings drop-down list to create a tag. JVM stands for Java virtual machine.

  1. Log on to the EDAS console.

  2. Create a group for an application. For more information, see Create an application instance group.

  3. Add an application instance to the new group. You can allocate an application instance in the default group to the new group, or scale out the new group. For more information, see Add an instance to an application instance group.

    Important

    After an application instance in the default group is allocated to the new group, you must restart the application instance. Otherwise, the system does not identify the tag. If you add application instances to scale out the new group, you do not need to restart the instances in the new group.

  4. In the upper-right corner of the new group, select JVM from the Group Settings drop-down list.

    Group Settings - JVM
  5. In the Group Settings dialog box, click Custom. In the Custom section, turn on the switch in the Custom column. In the Configuration Body field, configure a tag for the group and click Configure JVM Parameters.

    You must configure a tag in the Dalicloud.service.tag=tag1 format. tag1 indicates the tag name. Set the tag name based on your business requirements.

    Group Settings - JVM - Custom
  6. Use one of the following methods to restart the application.

    • Method 1: On the Applications page, select the applications that you want to restart and click Batch Restart. In the OK dialog box, click OK.

    • Method 2: On the Applications page, click the application that you want to restart in the Application Name column. In the upper-right corner of the Basic Information page, click Stop to stop the application or click Start to start the application.

    Note

    You must restart the application for custom JVM parameters to take effect.

Create a tag-based routing rule

After a tag is created, you can create a tag-based routing rule based on the tag.

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, choose Traffic Management > Microservices Governance > Spring Cloud.

  3. In the navigation pane of the Spring Cloud page, click Tag-based Routing.

  4. On the Tag-based Routing page, select a microservices namespace from the Microservice Namespace drop-down list and click Create Tag-based Routing.

  5. In the Create Tag-based Routing panel, set the parameters and click OK.

    Create tag-based routing

    The following table describes the parameters.

    Parameter

    Description

    Microservice Space

    Select a region and a microservices namespace based on your business requirements.

    Routing Rule Name

    Enter the name of the tag-based routing rule. For example, you can enter label-routing-group1.

    Description

    Enter a description for the tag-based routing rule.

    Application

    Select an application from the drop-down list.

    Tag

    Select a tag from the drop-down list. The tag is the value that you specify for the custom JVM parameter -Dalicloud.service.tag when you create a group for the application.

    After you select the tag, the IP address of the application instance in the group appears in the Application Instance section.

    Link Delivery

    Turn on Link Delivery if you want to enable end-to-end traffic adjustment.

    Note

    The end-to-end traffic adjustment feature is in canary release. If you need to use this feature, join the DingTalk group whose ID is 31723701 to contact EDAS technical support.

    Traffic Rules

    Framework Type

    Select the framework of the application. Valid values: Spring Cloud and Dubbo.

    • Spring Cloud: You can specify only a URL path, such as /getIp.

    • Dubbo: You can select a specific service and an interface.

    Path

    The relative path of HTTP.

    Condition Mode

    Select Meet All Conditions or Meet One of Conditions based on your business requirements.

    Conditions

    Select Parameter, Cookie, Header, or Body Content from the Parameter Type drop-down list. Examples:

    • If you select Parameter, you must specify the value in the name=xiaoming format in the Value column.

    • If you select Cookie, you must specify the value in the hello = "world" or hello = "world2" format in the Value column.

Verify the result

This topic provides an example on how to create tag-based routing rules for instances of an application. You can follow the instructions in this topic to configure tag-based routing rules for instances of your application and then verify the rules based on your business requirements.