Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand SpringCloud Hystrix source code parsing

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report