Service Routing Rules

Service Routing

Conditional Routing

The usage pattern is similar to the Conditional Routing Documentation, but the configuration format is slightly different. Below is an example of conditional routing rules.

Based on the following example rule, all calls to the greet method of the org.apache.dubbo.sample.tri.Greeter service will be forwarded to a subset of addresses marked with port=8888.

  1. configVersion: v1.0
  2. scope: "service"
  3. force: false
  4. enabled: true
  5. key: "org.apache.dubbo.sample.tri.Greeter"
  6. conditions:
  7. - method=greet => port=8888

Note:
The Dubbo Rust currently does not distinguish at the application level, and cannot differentiate the origin of the service.
Therefore, for tag routing and conditional routing, only one application-level configuration can be specified.
For application-level configuration, the default key is set to application, and this configuration will affect all services.
For example:

  1. configVersion: v1.0
  2. scope: "application"
  3. force: false
  4. enabled: true
  5. key: application
  6. conditions:
  7. - ip=127.0.0.1 => port=8000~8888

Match/Filter Conditions

Parameter Support

  • Service call context, such as: service_name, method, etc.
  • URL fields, such as: location, ip, port, etc.
  • Field information stored in URL params.

Condition Support

  • Equal sign = indicates “match”, e.g.: method = getComment
  • Not equal != indicates “no match”, e.g.: method != getComment

Value Support

  • Multiple values separated by comma, e.g.: ip != 10.20.153.10,10.20.153.11
  • Asterisk * at the end indicates a wildcard, e.g.: ip != 10.20.*
  • Integer value range, e.g.: port = 80~8080

Tag Routing

The usage pattern is similar to the Tag Routing Documentation, but the configuration format is slightly different. Below is an example of tag routing rules.

  1. configVersion: v1.0
  2. force: false
  3. enabled: true
  4. key: application
  5. tags:
  6. - name: local
  7. match:
  8. - key: ip
  9. value: 127.0.0.1

In this configuration, all service providers/consumers with ip=127.0.0.1 will be tagged with local.

Dynamic Configuration

Overview of Dynamic Configuration

Dynamic configuration uses Nacos as the configuration center. It needs to be configured in the project’s application.yaml file; if not configured, local routing configuration will be used.

Usage:

  1. nacos:
  2. addr: "127.0.0.1:8848"
  3. namespace: "namespace-name"
  4. app: "app-name"
  5. enable_auth:
  6. auth_username: username
  7. auth_password: password

app: the app where routing configurations are placed in Nacos. namespace: the namespace where configuration information is located in Nacos. addr: the Nacos service address. enable_auth: optional configuration; if Nacos’s authentication feature is enabled, this must be specified. auth_username corresponds to the account, auth_password to the key.

Configuring Conditional Routing

When creating conditional routing configurations in Nacos, app and namespace are the information input during Nacos configuration; group: fixed as condition; name: must match the service name;

Configuring Tag Routing

When creating tag routing configurations in Nacos,

app: the app filled in during Nacos configuration; namespace: the namespace filled in during Nacos configuration; group: fixed as tag; name: fixed as application;

Notes

Dubbo Rust does not currently differentiate at the application level and cannot identify the source of a service; therefore, application-level configurations will apply to all services by default. Thus, for tag routing and conditional routing, only one application-level configuration can be specified with the name designated as application.

Example:

nacos-example.png

Corresponding Configuration Items:

Service Level Conditional Routing Configuration:

  1. configVersion: v1.0
  2. scope: "service"
  3. force: false
  4. enabled: true
  5. key: "org.apache.dubbo.sample.tri.Greeter"
  6. conditions:
  7. - method=greet => ip=127.*

Tag Routing Configuration:

  1. configVersion: v1.0
  2. force: true
  3. enabled: true
  4. key: shop-detail
  5. tags:
  6. - name: local
  7. match:
  8. - key: ip
  9. value: 127.0.0.1

Application Level Conditional Routing Configuration:

  1. configVersion: v1.0
  2. scope: "application"
  3. force: false
  4. enabled: true
  5. key: application
  6. conditions:
  7. - ip=127.0.0.1 => port=8000~8888

Feedback

Was this page helpful?

Yes No

Last modified September 30, 2024: Update & Translate Overview Docs (#3040) (d37ebceaea7)