Fault Tolerance
Based on whether the retry interval is fixed, retry policies are classified into fixed interval and exponential interval. The default retry policy is fixed interval.
- Fault tolerance of Java chassis is used for microservice consumers. The fault tolerance module must be integrated into microservice applications and the bizkeeper processing chain must be enabled.
Configuration example:
servicecomb: handler: chain: Consumer: default: bizkeeper-consumer
Add the following dependency to the POM file:
<dependency> <groupId>org.apache.servicecomb</groupId> <artifactId>handler-bizkeeper</artifactId> <version>${project.version}</version> </dependency>
The microservice development framework Java Chassis 2.x is used as an example.
- Spring Cloud uses Aspect to intercept RequestMappingHandlerAdater to implement fault tolerance. After Spring Cloud Huawei is integrated, the client fault tolerance module spring-cloud-starter-huawei-governance is integrated by default. You only need to enable a specific client fault tolerance policy.
servicecomb: matchGroup: AllOperation: | matches: - apiPath: prefix: "/" retry: AllOperation: | maxAttempts: 3 # Number of retries retryOnSame: 1 # Instance initiated by retry retryOnResponseStatus: # Retry error code - 502 - 503
The default policy takes effect when the error code is 502 or 503. In 1.11.4-2021.0.x/1.11.4-2022.0.x and later versions, the response header takes effect in special scenarios.
The response header is defaulted to X-HTTP-STATUS-CODE. You can also customize the key as follows:
spring: cloud: servicecomb: governance: response: header: status: key: 'X-HTTP-EEROR-STATUS-CODE'
The response code set in the response header can also be customized. However, you need to add the corresponding error code to the fault tolerance policy. For example, if you set X-HTTP-STATUS-CODE=511, add error code 511. The configuration is as follows:
servicecomb: matchGroup: AllOperation: | matches: - apiPath: prefix: "/" retry: AllOperation: | maxAttempts: 3 # Number of retries retryOnSame: 1 # Instance initiated by retry retryOnResponseStatus: # Retry error code - 502 - 503 - 511
The system checks the response code first. If the abnormal response code meets the policy setting, the fault tolerance function is enabled. If the abnormal response code does not meet the policy setting, the system checks whether the response code set in the header meets the requirement.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot