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.
Take xml configuration as an example: (configuration through annotations is similar)
mock="true"
example:
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" 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 com.xxx.service
package.
mock="com.xxx.service.DemoServiceMock"
example:
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="com.xxx.service.DemoServiceMock" />
This method specifies the full path of the Mock class.
mock="[fail|force]return|throw xxx"
example:
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="return" />
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="return null" />
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="fail:return aaa" />
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="force:return true" />
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="fail:throw" />
<dubbo:reference id="demoService" interface="com.xxx.service.DemoService" mock="force:throw java.lang.NullPointException" />
Introduce dubbo-mock-admin
< /a>dependency
Set the JVM parameters when the application consumer starts, -Denable.dubbo.admin.mock=true
Start dubbo-admin, set the Mock rule under the service Mock->rule configuration menu
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
The configuration format is wrong, such as return+null
will report an error, and it will be treated as a mock type. return
can be omitted or followed by a space followed by the return value
Type not found error, such as custom mock class, throw custom exception, please check if the type exists or if there is a typo