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

What is the relationship among Feign/Ribbo/Hystrix?

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the relationship among Feign/Ribbo/Hystrix". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the relationship among Feign/Ribbo/Hystrix".

I. Preface

In the application of micro-service architecture, Feign and Hystrix,Ribbon are indispensable, which can be said to have become an iron triangle.

II. Introduction to Feign

Feign is a HttpClient binder written in Java language, which is used to implement declarative invocation between microservices in Spring Cloud microservices. Feign can define interfaces for requests to other services, which can be used for calls between micro-services. Instead of writing http requests on the client side, calling this interface is like calling other services remotely. When the request goes wrong, you can call the implementation class of the interface to return.

Feign is a declarative web service client that makes it easier to write web service clients. You can use Feign by creating an interface and annotating it. Feign can use Feign annotations or JAX-RS annotations, and supports hot-swappable encoders and decoders. Spring Cloud adds Spring MVC annotation support for Feign and integrates Ribbon and Eureka to provide load balancing when using Feign.

II. Introduction to Ribbon

Ribbon, as a load balancer, is implemented on the client side. The service segment can start services with different ports but the same servername.

Ribbon is an open source project released by Netflix, and its main function is to provide software load balancing algorithms on the client side to connect the middle-tier services of Netflix. The Ribbon client component provides a complete set of configuration items such as connection timeout, retry, etc. To put it simply, list all the machines behind Load Balancer in the configuration file, and Ribbon will automatically help you connect these machines based on certain rules (such as simple polling, random connection, etc.). We can also easily implement custom load balancing algorithms using Ribbon. Simply put, Ribbon is a client-side load balancer.

Ribbon works in two steps:

Step 1: choose Eureka Server first, which gives priority to Server with less load and in the same Zone.

Step 2: according to the policy specified by the user, select an address from the service registration list obtained from Server. Ribbon provides a variety of strategies, such as polling, random, weighted according to response time, and so on.

III. Introduction to Hystrix

As a fuse flow control, Hystrix is implemented on the client side and annotated on the method. When an error occurs in the request, you can call the method in the annotation to return.

Hystrix fuses, fault-tolerant management tools, are designed to control the nodes of services and third-party libraries through fuse mechanisms, thus providing greater fault tolerance for delays and failures. A series of service protection functions such as thread isolation and circuit breaker are realized in Spring Cloud Hystrix. It is also implemented based on Netflix's open source framework Hystrix, which aims to provide stronger fault tolerance for delays and failures by controlling nodes that access remote systems, services, and third-party libraries. Hystrix has powerful functions such as service degradation, service breaker, thread isolation, request caching, request merging and service monitoring.

Fourth, the relationship between the three diagrams

If spring-cloud-starter-netflix-hystrix dependencies are added to the microservice project, feign automatically wraps all methods in hystrix through the proxy mode.

Under the Spring Cloud micro-service system, the mutual invocation between micro-services can be invoked declaratively through Feign. In the process of service invocation, Feign will obtain the server address list of the target micro-service from the service registry through Ribbon, and then Ribbon will call the request to different instances of micro-service in a load-balanced manner during the network request. In order to achieve the most critical function of Spring Cloud micro-service architecture, namely service discovery and client load balance invocation.

On the other hand, in the process of mutual invocation of micro-services, in order to prevent the failure of one micro-service from consuming the connection resources of all micro-services of the whole system, so in the process of implementing micro-service invocation, we will require the caller to implement the circuit breaker logic for the called micro-service. To implement this logical scenario, we use the framework of Hystrix under the framework of Spring Cloud micro-services.

The caller will set the call timeout for the microservice to be called. Once the timeout occurs, it will enter the circuit breaker logic, and this fault indicator information will also be returned to the Hystrix component. The Hystrix component will judge the fault of the tuned service according to the circuit breaker condition and open the fuse, and then all requests for the microservice will directly enter the fuse logic until the fault of the tuned service resumes and the Hystrix circuit breaker closes.

The relationship between the three is roughly as follows:

Thank you for your reading, the above is the content of "what is the relationship between Feign/Ribbo/Hystrix and Feign/Ribbo/Hystrix". After the study of this article, I believe you have a deeper understanding of what the relationship between Feign/Ribbo/Hystrix is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Servers

Wechat

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

12
Report