Dubbo provides the service governance capability of dynamically creating conditional routing, which can route according to the request initiator and method without restarting the application.
Dubbo can implement dynamic routing according to request conditions through XML configuration, annotation configuration, and dynamic configuration. Here we mainly introduce the dynamic configuration method. For other configuration methods, please refer to the old document Configuration
before the start
Please make sure to run Dubbo-Admin successfully
In business scenarios such as black and white lists, excluding pre-release machines, exposing only some machines, and isolation by environment, routing rules are required to filter the target server address before initiating an RPC call, and the filtered address is used as the candidate address for the final RPC call. Dubbo-Admin provides conditional routing capabilities, which can help you configure routing rules to meet business scenarios.
- Log in to the Dubbo-Admin console
- In the left navigation pane, select Service Governance > Conditional Routing.
- Click the Create button, in the Create New Routing Rule panel, fill in the rule content, and then click Save.
--- scope: application/service force: true runtime: true enabled: true key: app-name/group+service+version conditions: - application=app1 => address=*:20880 - method=sayHello => address=*:20880
For conditional routing scenarios, you only need to clarify the following questions to know how to write the configuration:
- To modify the configuration of the consumer application or the configuration of a service.
scope: application, key: app-name(you can also use
servicesto specify certain services).
scope: service, key:group+service+version.
- When the routing result is empty, whether to force return.
- force=false: When the routing result is empty, downgrade the provider whose tag is empty.
- force=true: When the routing result is empty, an exception will be returned directly.
- Priority of routing rules
- priority=1: The priority of routing rules, used for sorting, the higher the priority, the higher the execution, it can be left blank, the default is 0.
- Whether the configuration takes effect only for certain specific instances.
- All instances:
addresses: ["0.0.0.0:*"]depends on the side value.
- Specified instances:
addersses[list of instance addresses].
- All instances:
- The condition rule to modify.
- => The previous one is the consumer matching condition. All parameters are compared with the consumer’s URL. When the consumer meets the matching condition, the subsequent filtering rules are executed for the consumer.
- => After that, it is the filter condition of the provider’s address list. All parameters are compared with the provider’s URL, and consumers only get the filtered address list in the end.
- If the matching condition is empty, it means to apply to all consumers, such as: => host != 10.20.153.11
- If the filter condition is empty, access is prohibited, such as: host = 10.20.153.10 =>
Select the application related to the conditional routing configuration to trigger the call verification.