Service routing

更新时间:
复制 MD 格式

Routing rules determine which service provider handles a request when a consumer can choose from multiple providers. With the service routing feature, you can define flexible rules to solve challenges in various scenarios.

Features

Service routing is often used for offline integration testing, blue-green deployments, and canary releases. It helps minimize the impact of issues caused by version upgrades.

  • Offline integration testing

    During offline testing, you may not have the required environment. You can register the test application online and then enable routing rules to test it locally.

  • Blue-green deployment

    For blue-green deployments, you can use routing rules to switch traffic to the green group to test the new application version.

  • Canary release

    For canary releases, you can use routing rules to direct traffic to the canary application version to test its stability.

Note

Currently, routing is supported only for SOFA and Dubbo services. Spring Cloud services are not supported.

Routing rules are configured on the service consumer (client) to filter service providers. The two main execution entities are RPC-Client for classic microservices and MOSN for service mesh.

When you deploy a service provider, you can add a tag in a fixed format to the machine, such as LABEL=A.mv The following diagram shows the workflow for a routing rule:版本号

Add a routing rule

  1. Log on to the SOFAStack console.

  2. In the navigation pane on the left, choose Middleware > Microservice Platform > Microservices > Service Administration, and then click the Service Routing tab.

  3. Click Add Routing Group Rule and configure the following parameters:

    Area

    Parameter

    Description

    Basic information

    Rule group name

    Enter a name for the routing rule group.

    Provider application name

    Enter the name of the server-side application.

    Service

    Specify the services in the application.

    Click Switch Input Mode to toggle between manual entry and selection from a list.

    Rule properties

    Rule name

    Enter a name for the routing rule.

    Priority

    Set the route priority. A higher number indicates a higher priority.

    If multiple routes exist, they are matched in order of priority.

    Rule switch

    Specifies whether to enable the rule. This is enabled by default.

    Diversion switch

    Specifies whether to forward traffic to other groups if the destination group has no service instances.

    • If enabled, traffic continues to match other groups when no service instance is found in a high-weight group.

    • If disabled, traffic does not match other groups.

    Fallback switch

    Specifies whether to match other rules if the current rule fails to match any service instance.

    • If enabled, traffic continues to match lower-priority routing rules.

    • If disabled, traffic does not match other routing rules.

    Exact traffic match (Optional)

    Use traffic matching conditions to filter requests that must follow this routing rule. Traffic that meets these conditions uses this rule. Traffic that does not meet the conditions follows the fallback switch logic and attempts to match lower-priority rules. If you leave this blank, all traffic is matched.

    Multiple conditions are executed in order until a rule intercepts the traffic or all conditions are met. The rule includes the following main components:

    • Field: Includes system fields, request headers, and trace links.

    • Field name: The value depends on the field type.

      • System fields: Include traffic type, caller application name, caller IP, and provider application name.

      • Request header: Refers to the protocol's request header. For example, the Dubbo protocol uses attachments, and the HTTP protocol uses request headers. You can define custom request header parameters and values in your application.

      • Trace link: Refers to trace information obtained from the configuration file in the code.

    • Logic: Includes equals, does not equal, belongs to, does not belong to, and regex.

    • Field value: The value corresponding to the field name.

    Traffic destination

    Weight

    Set the weight for the current destination group. The sum of weights for all destination groups must be 100%.

    Click Add at the bottom to configure multiple destination groups.

    Service instance grouping condition

    Define the conditions for grouping service instances. Multiple conditions are combined with an AND operator.

    • Field name: Select from the drop-down list or enter a custom value.

    • Logic: Equals.

    • Field value: Enter the value for the field name.

    Click Add below to configure multiple conditions.

  4. Click Submit.

  5. In the service routing list, change the status of the newly created routing rule to Enabled.

Important

You can add multiple routing rules. Rules for the same application name are merged.

Edit a routing rule

You can edit an existing routing rule at any time. The changes take effect immediately after you submit them.

  1. On the Service Routing tab, click the plus sign (+) to the left of the target application.

  2. Click Edit to the right of the target routing rule.

  3. Edit the routing rule as needed, and then click Submit.

Delete a routing rule

You can delete an existing routing rule. The deletion takes effect immediately. Proceed with caution.

  1. On the Service Routing tab, click the plus sign (+) to the left of the target application.

  2. Click Delete to the right of the target routing rule.

  3. Click OK.