SpringCloud-Hystrix service degradation and circuit breaker

Continuing from the above article SpringCloud-Feign

Problem Description

Insert image description here
Insert image description here
To solve the above situation, SpringCloud provides Hystrix fuse component, which is like a fuse. Service degradation does not directly return an error, but provides a remedial measure and responds normally to the requester.

1. Service downgrade

Based on the borrowing management service, users and books are not enabled, that is, both are down.
Import Hystrix dependencies (this project has stopped maintaining, and SpringCloud dependencies are no longer included).
Insert image description here
Add annotations to the startup class Insert image description here
to close the user and book services. If the query information is not available at this time, an alternative is provided. That is, when an exception occurs in the service, our alternative is returned.
Insert image description here
Restart the borrow-service service.
Insert image description here
At this time, accessing the borrowing information interface returns empty.
Insert image description here

2.Service circuit breaker

Insert image description here
Insert image description here
After restarting, I kept visiting http://localhost:8201/borrow/1 and found that the method would be executed normally at first, and then I remedied it. As the number of clicks increases, only remediation is performed. Clicking again after a while will perform the normal method to remedy the situation. That is, fuse. Insert image description here
Then enable user services and book services. At this time, after the service is restored, the two service methods will be executed normally, and the circuit breaker mechanism will be turned off.Insert image description here

Insert image description here

Summarize
Insert image description here

3.openfeign implements downgrade

Openfeign downgrade is a service downgrade after failure to access a controller method. At this time, the user service will be hung up, but the book service will not be hung up. If the borrowing information is checked, the user service call will fail. At this time, the user service will be given an alternative.
Insert image description here

Insert image description here
Add configuration in the borrow-service configuration file to support circuit breaker
Insert image description here
Insert image description here

Close the user-service and restart the borrow-service Insert image description here
. There are remedial measures for user-service to hang up. The remedial measures for book-service are the same.
Insert image description here

4.Hystrix monitoring

Create a new module,
Insert image description here
Insert image description here
Insert image description here
Insert image description here
start the Hystrix management page service, add dependencies to the monitored service,
Insert image description here
Insert image description here
and restart the service.
Insert image description here

It can be accessed normally.
Insert image description here
Start the monitoring service.
Insert image description here
You can view the management page Insert image description here
. Enter the service to be monitored at the intermediate level, such as the borrowing service: http://localhost:8201/actuator/hystrix.stream, and then click monitor stream to view the service, as shown in the figure.
Insert image description here
The monitoring page will change after accessing the interface.

**If you need the source file, you can follow it and deduct 1 below, and it will be sent privately.

Guess you like

Origin blog.csdn.net/weixin_43917045/article/details/132745100