Get the App
SLTechnology News&Howtos  ›  Development  › 

How to understand SpringCloud Hystrix source code parsing

Shulou Source: shulou.com Published: 2022-06-03 02:43:38 09月14日 Update

This article focuses on "how to understand SpringCloud Hystrix source code analysis", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "how to understand SpringCloud Hystrix source code parsing"!

SpringCloud Hystrix source code parsing

Please read this article before you read it

Five minutes to learn Spring Cloud Hystrix: service fault-tolerant protection (Xiaobai must see, a look will be a series of tutorials)

The remote invocation process after using Hystrix is as follows:

1) build HystrixCommand or Hys trixObservableCommand objects.

2) execute the command.

3) check whether there is a cache for the execution of the same command.

4) check whether the circuit breaker is turned on.

5) check whether the thread pool or semaphore is consumed.

6) call Hystri xOb servabl eCommand#construct or Hystri xCommand#run to execute the encapsulated remote call logic.

7) calculate the health of the link.

8) get Fallback logic when command execution fails.

9) return the successful Observable.

Encapsulated HystrixCommand

@ HystrixCommand comment

In basic applications, we use the @ HystrixCommand annotation to wrap remote invocation methods that need to be protected. First, take a look at the relevant properties of the annotation, and the code is as follows:

/ / HystrixComrnand. Java@Target ({Element Type. METHOD}) @ Retentio port (RetentionPolicy. RUNTIME) @ Inherited@Document edpu b l worker C @ int er face Hys tr ixComrnand {/ / Command grouping key for reporting, warning, and panel display / / default to the run-time class name of the annotated method, String groupKey () default//, the command key for ystr worker X Used to distinguish between different annotation methods / / default is the name of the annotation method String commandKey () default// thread pool key is used to specify the HystrixTh readPoolStr worker ng threadPoolKey () default "" for command execution Chapter 6 Circuit Breaker Hystrix! 125 default / specify the name of the Fallback method, and the Fallback method can also be annotated by HystrixCommand for the relevant configuration of the String fallbackMethod () default// custom command HystrixProperty [) commandProperties () default {}; / / customize the relevant configuration of the thread pool HystrixProperty [J threadPoolProperties () default {}; / / define which exception Class to ignore.

Tags: Methods commands annotations caching results configurations signals semaphores encapsulation circuit breakers threads checks subscriptions isolation types logic differences synchronization source code methods Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Docker NVidia MariaDB