Help Center> ServiceStage> Developer Guide> Spring Cloud Huawei> Implementing Route Management

Implementing Route Management

For route management, flexible route definition rules are provided, which can be used to implement dark launch easily.

Prerequisite

The local lightweight microservice engine is downloaded.

Getting Started

  1. Add the following dependencies for route management.

    <dependency> 
      <groupId>com.huaweicloud</groupId> 
      <artifactId>spring-cloud-starter-huawei-router</artifactId> 
    </dependency>

  2. Create a project or module and define a configuration file.

    You can configure routing rules by setting the application.yml file. For details, see Route Management Rules.

    servicecomb:
      routeRule:
        canary-provider: |
          - precedence: 1 #Priority.
            route: #Routing rule.
              - weight: 80
                tags:
                  version: 0.0.1
              - weight: 20
                tags:
                  version: 0.0.2
    

  3. Start services. The traffic is then allocated based on the configuration.

Running the Demo

The following shows how to implement dark launch based on a project demo. spring-cloud-huawei-sample/canary-demo is used to simulate the scenario where ServiceStage is used to implement dark launch in a Spring Cloud project.

  1. Respectively modify the application.yml files of the canary-consumer, canary-provider, and canary-provider-beta projects. For the canary-consumer project, you also need to configure the bootstrap.yaml file for connecting to the configuration center.

    The following lists the configuration items in the application.yaml file.

    server:
      port: 8091
    spring: 
      application: 
        name: consumer 
      cloud: 
        servicecomb: 
          discovery: 
            enabled: true #Enable service discovery.
            address: https://cse.cn-north-4.myhuaweicloud.com:443  #Registry center address.
            version: 0.0.2 #Service version.
            healthCheckInterval: 30 #Heartbeat interval.
            autoDiscovery: true # Avoid domain name resolution in the same Virtual Private Cloud (VPC).
          credentials: 
            enabled: true # Enable IAM authentication.
            accessKey: yourak # Access Key ID (AK).
            secretKey: yoursk # Secret Access Key (SK).
            project: cn-north-4 # Region.
            akskCustomCipher: default
    

    The bootstrap.yaml file is used to specify the configuration center address.

    spring: 
      application: 
        name: consumer  
      cloud: 
        servicecomb: 
          config: 
            serverAddr: https://cse.cn-north-4.myhuaweicloud.com # Configuration center address.
            watch: 
              delay: 10000 
          credentials: 
            enable: true # Enable IAM authentication.
            accessKey: yourak # AK.
            secretKey: yoursk # SK.
            akskCustomCipher: default # Region.
            project: cn-north-4
    

    For the canary-consumer project, you can also configure dark launch rules in the application.yaml file and change routes to achieve expected traffic allocation. In addition, dark launch supports both Feign and Hystrix, and no additional reference or configuration is required. Example:

    servicecomb: 
      routeRule: 
        canary-provider: | 
          - precedence: 2 #Priority.
            route: #Routing rule.
              - weight: 100 
                tags: 
                  version: 0.0.1 
    

  2. Respectively start the canary-consumer, canary-provider, and canary-provider-beta services.
  3. Implement verification.

    Access the following address:

    http://127.0.0.1:8091/canary?id=11

    The traffic is allocated as expected.

The following table lists the configuration items in the application.yaml file.

Configuration Item

Key

Default Value

Header key to be transparently transmitted. The specified header can be transparently transmitted to all downstream microservices for route management. It is of the array type.

servicecomb.router.header

[]

Route rules setting for a specified calling service

servicecomb.routeRule.[provider]

-