When a cloud-native gateway receives a request, the gateway evaluates the configured routing rules from the highest priority to the lowest priority. The gateway forwards the request to the destination service that is configured in the first rule that the request matches. If the request matches no rule, the gateway returns HTTP status code 404.
Prerequisites
An existing cloud-native gateway instance.
An existing domain name for the route to match, or a domain name that you create while you configure the route.
An existing service source that provides the backend service of the route.
Limits
The following limits apply when you create a route:
Service sources — If Source Type is set to MSE Nacos or MSE Zookeeper, you can add only one source. If Source Type is set to Container Service, you can add up to five sources. If Source Type is set to EDAS Built-in Registry or SAE Built-in Registry, the number of sources is unlimited.
Traffic weights — The sum of the traffic percentages of the destination services that use weights must be 100%.
Fallback — Fallback is supported only between HTTP services.
Procedure
Log on to the MSE console. In the top navigation bar, select a region.
In the left-side navigation pane, choose Cloud-native Gateway > Gateways. On the Gateways page, click the ID of the gateway.
In the left-side navigation pane, click Routes. On the Routes tab, click Add Route.
On the Add Route page, configure the parameters that are described in Route parameters and then click Save.
Route parameters
The following table describes the parameters that you configure when you create a route.
| Parameter | Description |
| Route Name | A custom name for the route. You can also click Add Description to describe the route. |
| Domain Name | Select the domain names that you want to match for the route. You can select multiple domain names. To create a domain name, click Add Domain Name and create the domain name in the panel that appears. |
| Match Rule | The matching rules are combined by a logical AND. The more rules you specify, the smaller the range of requests that are matched. For more information about how matching rules are ranked, see Route matching priorities. |
| Path | Specify the Path parameter that is used to match HTTP requests. If routes use the same matching rule, the longer the Path value, the higher the priority. If routes use different matching rules, the priority is as follows: Equal To > Prefix > Regular Expression Match. Equal To: an exact match. For example, the Path value equals /user. Prefix: uses a prefix as the matching condition. For example, the Path value starts with /user. Regular Expression Match: uses a regular expression as the matching condition. |
| Method | Specify the Method parameter that is used to match HTTP requests. You can select multiple HTTP methods. The default value is ANY. |
| Header | Specify the Header parameter that is used to match HTTP requests. If routes use the same matching rule, the larger the total number of key-value pairs, the higher the priority. |
| Query Parameters | Specify the Query parameter that is used to match HTTP requests. If routes use the same matching rule, the larger the total number of key-value pairs, the higher the priority. |
| Scenario | Select the type of the destination service for the current route. Basic scenarios: Single Service. Canary release scenarios: Multiple Services and Tag-based Routing. Other scenarios: Mock and Redirect. For more information about the types of destination services, see Routing modes. |
| Backend Service | Select an associated backend service and a port. Click Associate Service to select a source and a service in the panel that appears. The number of sources that you can add varies based on the source type. For details, see Limits. |
| Fallback | Specify a fallback service based on your business requirements. If no node is available for the backend service to which the route points, the original request accesses the fallback service that you specify here. |
| Timeout Period (s) | Enter a timeout period. The default value is 60 seconds. A value of 0 specifies that the request never times out. |
| Number of Retries (times) | Enter the number of retries. The default value is 2. A value of 0 disables retries. |
| Retry Conditions | Select the retry conditions. |
| Retry Status Code | Add one or more retry status codes. |
Route matching priorities
If multiple routing rules exist, the rules are sorted from the highest priority to the lowest priority in the following order: Domain Name > Path > request header > Query Parameters > Created At. The following rules apply:
Domain Name: The longer the domain name string, the higher the priority.
Path:
If the Match Rule is different, the priority is as follows: Equal To > Prefix > Regular Expression Match.
If the Match Rule is the same, the longer the Path string, the higher the priority.
Header: The larger the total number of key-value pairs, the higher the priority.
Query Parameters: The larger the total number of key-value pairs, the higher the priority.
Creation time: The earlier a route is created, the higher the priority of the route.
The matching priority of routes is the same as the order in which the routes are displayed on the route configuration page.
References
You can modify routing rules at any time based on your actual scenarios and changing requirements. For instructions, see Modify a routing rule.