Service Downgrade

Downgrade Dubbo service

Feature description

It is recommended to use relevant current limiting and downgrading components (such as Sentinel) to achieve the best experience. Reference example practice: Microservice Governance/Limit and Downgrade

Service degradation refers to the emergency treatment of service degradation under abnormal circumstances.

scenes to be used

  • When the load of a certain service or interface exceeds the maximum carrying capacity range, downgrade emergency treatment is required to avoid system crash
  • When a non-critical service or interface called is temporarily unavailable, simulated data or null is returned, and the business can continue to be available
  • Downgrade non-core business services or interfaces, free up system resources, and try to ensure the normal operation of core business
  • When an upstream basic service times out or is unavailable, execute a downgrade plan that can respond quickly to avoid the overall avalanche of services

How to use

Take xml configuration as an example: (configuration through annotations is similar)

1. Configure mock="true"


<dubbo:reference id="demoService" interface="" mock="true" />

This method requires an implementation class with the class name + Mock suffix under the same package, that is, there is a DemoServiceMock class under the package.

2. Configure mock=""


<dubbo:reference id="demoService" interface="" mock="" />

This method specifies the full path of the Mock class.

3. Configure mock="[fail|force]return|throw xxx"

  • The fail or force keyword is optional, indicating that the call fails or does not call to enforce the mock method, if no keyword is specified, the default is fail
  • return indicates the specified return result, and throw indicates that the specified exception is thrown
  • xxx is parsed according to the return type of the interface, you can specify the return value or throw a custom exception


<dubbo:reference id="demoService" interface="" mock="return" />
<dubbo:reference id="demoService" interface="" mock="return null" />
<dubbo:reference id="demoService" interface="" mock="fail:return aaa" />
<dubbo:reference id="demoService" interface="" mock="force:return true" />
<dubbo:reference id="demoService" interface="" mock="fail:throw" />
<dubbo:reference id="demoService" interface="" mock="force:throw java.lang.NullPointException" />

4. Use with dubbo-admin

Set rules in the dimension of service methods, set return mock data, and dynamically enable/disable rules


When Dubbo starts, it will check the configuration. When the configuration of the mock attribute value is wrong, it will fail to start. You can troubleshoot according to the error message