Class ConditionStateRouter<T>

java.lang.Object
org.apache.dubbo.rpc.cluster.router.state.AbstractStateRouter<T>
org.apache.dubbo.rpc.cluster.router.condition.ConditionStateRouter<T>
All Implemented Interfaces:
StateRouter<T>

public class ConditionStateRouter<T> extends AbstractStateRouter<T>
Condition Router directs traffics matching the 'when condition' to a particular address subset determined by the 'then condition'. One typical condition rule is like below, with 1. the 'when condition' on the left side of '=>' contains matching rule like 'method=sayHello' and 'method=sayHi' 2. the 'then condition' on the right side of '=>' contains matching rule like 'region=hangzhou' and 'address=*:20881'

By default, condition router support matching rules like 'foo=bar', 'foo=bar*', 'arguments[0]=bar', 'attachments[foo]=bar', 'attachments[foo]=1~100', etc. It's also very easy to add customized matching rules by extending ConditionMatcherFactory and ValuePattern

--- scope: service force: true runtime: true enabled: true key: org.apache.dubbo.samples.governance.api.DemoService conditions: - method=sayHello => region=hangzhou - method=sayHi => address=*:20881 ...

  • Field Details

  • Constructor Details

    • ConditionStateRouter

      public ConditionStateRouter(org.apache.dubbo.common.URL url, String rule, boolean force, boolean enabled)
    • ConditionStateRouter

      public ConditionStateRouter(org.apache.dubbo.common.URL url)
  • Method Details

    • init

      public void init(String rule)
    • isRuntime

      public boolean isRuntime()
      Description copied from interface: StateRouter
      To decide whether this router need to execute every time an RPC comes or should only execute when addresses or rule change.
      Specified by:
      isRuntime in interface StateRouter<T>
      Overrides:
      isRuntime in class AbstractStateRouter<T>
      Returns:
      true if the router need to execute every time.