When a Cloud-native API Gateway instance receives access requests, it matches the requests with routes one by one based on the priorities of routing rules. The gateway matches the requests with routes based on the priorities of routing rules in descending order. If a request matches a route, the request is routed to the destination service. If the request fails to match a route, the error code 404 is returned.
Route matching priorities
If multiple routing rules exist, the priorities of the routing rules are sorted in the following order from the highest to the lowest: associated domain name > path > request header > request parameters > creation time.
Determine the priority of a route based on its domain name. The longer the length of the domain name string of a route, the higher the priority of the route.
Determine the priority of a route based on the path of the route in the following scenarios:
If the path matching rules of multiple routes are different, the priorities of the routes are sorted based on the following conditions from the highest to the lowest: equal to > prefix match > regex match.
If the path matching rules of multiple routes are the same, the longer the path string of a route, the higher the priority of the route.
Determine the priority of a route based on the total number of key-value pairs in the request header for the route. The larger the total number of key-value pairs in the request header for a route, the higher the priority of the route.
Determine the priority of a route based on the total number of key-value pairs in the request parameters for the route. The larger the total number of key-value pairs in the request parameters for a route, the higher the priority of the route.
Determine the priority of a route based on its creation time. The earlier the creation time of a route, the higher the priority of the route.
Procedure
Log on to the Cloud-native API Gateway console.
In the left-side navigation pane, click API. In the top navigation bar, select a region.
Click the target API and click Create Route in the upper-left corner.
On the Add Route page, configure the parameters and click Save.
NoteA route is matched when all conditions in the routing policy are met. If you specify more conditions, fewer requests can be matched.
A request matches routes based on the order that is displayed on the Routes tab. The following table describes the route parameters.
Parameter
Description
Route Name
The name of the route that you want to create. You can click Add Route Description and enter a description for the route in the Route Description field.
Domain Name
One or more domain names that you want to match for the route.
If you want to create a domain name, click Add Domain Name and configure the parameters to create a domain name in the Add Domain Name panel.
Path
The Path parameter in the HTTP requests that you want to forward in the route.
If the path matching rules of multiple routes are the same, the longer the Path value of a route, the higher the priority of the route.
If the path matching rules of multiple routes are different, the priorities of the routes are sorted based on the following conditions from the highest to the lowest: Equals To > Prefix > Regular Expression Match.
Equals To: A complete path is used to match requests with a route. For example, you can set the Path parameter to
/user.Prefix: A path prefix is used to match requests with a route. For example, you can use the
/userprefix to match requests with a route.Regular Expression Match: A regular expression is used to match requests with a route.
More Match Rules
Method
The HTTP method that is used to match HTTP requests with a route. You can specify multiple values for the Method parameter to match more requests with a route. By default, ANY is selected.
Header
The Header parameter that is used to match HTTP requests with a route. If multiple routes have the same matching rule, the route that has a larger number of Header parameters in the rule has a higher priority.
Query Parameters
The Query parameter that is used to match HTTP requests with a route. If multiple routes have the same matching rule, the route that has a larger number of Query parameters in the rule has a higher priority.
Instance and backend service
Instance
The instance in which the route takes effect.
Scenarios
The type of the destination service for the route.
Basic Scenario: Single Service
Canary Release Scenario: Percentage (Multi-service) and Tag (Tag-based Routing)
Other Scenarios: Mock and Redirect
For more information about the types of destination services, see Routing modes.
NoteThe sum of the traffic percentages of the destination services must be 100%.
Backend Services
The associated backend service and port.
NoteYou can click Create Service in the Service Name drop-down list to select a source and a service in the Associated Service panel.
The number of sources that can be added varies based on the source type.
If Source Type is set to ACK, a maximum of five sources can be added.
If Source Type is set to MSE Nacos or MSE Zookeeper, only one source can be added.
Policy Configuration
Timeout Period (seconds)
The timeout period. The default value is 60. If you set this parameter to 0, no timeout occurs.
Fallback
Specifies whether to enable fallback 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 specified.
NoteFallback is supported only between HTTP services.
Retry Times
The number of retries that are allowed. Default value: 2. A value of 0 indicates that retry is not allowed.
Retry Condition
The retry condition.
Retry Status Code
The retry status code. You can add one or more retry status codes.