All Products
Search
Document Center

Microservices Engine:Create a routing rule

Last Updated:Feb 05, 2024

When a cloud-native gateway receives access requests, the gateway 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 sequence in descending order: associated domain name > path > request header > request parameters > creation time.

  1. 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.

  2. Determine the priority of a route based on the path matching rule of the route:

    • If the path matching rules of two routes are different, determine the priorities of the routes based on the following conditions in sequence: exact match > prefix match > regular expression match.

    • If the path matching rules of two routes are the same, the longer the path string of a route, the higher the priority of the route.

  3. 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.

  4. 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.

  5. 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

Note

Route configurations support HTTPs, including HTTP 1.0, HTTP 1.1, HTTP 2.0, gPRC, and WebSocket.

  1. Log on to the MSE console.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. In the top navigation bar, select a region.

  3. On the Gateways page, click the name of the gateway.

  4. In the left-side navigation pane, choose Routes > Route Settings. In the upper-left corner of the Route Settings page, click Add Route.

    1. In the Add Route panel, configure the parameters and click Next.

      Note
      • A route is matched when all conditions in the routing rule 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 page.

      Parameter

      Description

      Route Name

      The name of the route that you want to create.

      Domain Name

      The domain name that you created on the Domain Names page in the MSE console. You can select multiple domain names.

      Match Rule

      Path

      The Path parameter in the HTTP requests that you want to forward in the route.

      • If multiple routes have the same matching condition for the Path parameter, the route that has a longer Path value in the rule has a higher priority.

      • The matching conditions for the Path parameter include Exact Match, Prefix Match, and Regular Expression Match with the priority in descending order.

        • Exact Match: A complete path is specified to match requests with a route. For example, you can specify the path as /user.

        • Prefix Match: The prefix of a path is specified to match requests with a route. For example, you can specify the prefix as /user.

        • Regular Expression Match: A regular expression is used to match requests with a route.

      Method

      The Method parameter that is used to match HTTP requests with a route. If you do not configure this parameter, requests with any Method parameter value can match the route. You can specify multiple Method values in the matching condition to match more requests with a route.

      Header

      The Header parameter that is used to match HTTP requests with a route. If multiple routes have the same matching conditions aside from the number of specified Header parameters, a route that has a larger number of the Header parameters in the rule has a higher priority. Click Request Header to add a Header parameter in the routing rule.

      Query Parameters

      The Query parameter that is used to match HTTP requests with a route. If multiple routes have the same matching conditions aside from the number of specified Query parameters, a route that has a larger number of the Query parameters in the rule has a higher priority. Click Request Parameters to add a Query parameter in the routing rule.

    2. Configure parameters in the Destination Service step and click Save and Release.

      Parameter

      Description

      Destination Service

      The type of the destination service for the route. Valid values: Single Service, Multiple Services, Tag-based Routing, Mock, and Redirect. For more information about the types of destination services, see Routing modes.

      Note

      The sum of the traffic percentages of the destination services for which you configure the weight must be 100%.

References

You can modify routing rules at any time based on your business requirements. For more information, see Modify a routing rule.