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 core architecture principle of Spring Cloud?

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

What is the core architecture principle of Spring Cloud? I believe many inexperienced people are at a loss about it. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Recently in some distributed series of interview content, a few months in advance to prepare, you know, also share with you. Now distributed systems are basically standard, if you are still playing stand-alone, have not touched these things, the right to open a new door for you.

How many eggs hurt in a large single project?

In the past, when we did a stand-alone system, all the code was in the same project, but different modules were divided according to the package name. We used to do a provincial education project, there are student information and employment system, a university training system, a human resources system, and so on a total of six, four partners are developed in one code, there is a certain relationship between the various systems, but most of them are irrelevant, but the management pages are together.

At that time, we were all coding in the same project for several minutes at a time, and there was the problem of package version conflict, which really hurt. We have experienced large-scale single project development, I believe you have the experience.

The usage of each system is also different, and some of them are relatively large. For example, the student information and employment system is for all colleges and universities, especially during the period when they are about to graduate, each school will report information such as the employment rate, and print registration cards and so on. Some systems are less used, such as human resources, training systems are basically used by some staff of the Education Department, and some teachers, the flow is not large, can barely bear it.

Simulated business background

Larger enterprises, such as e-commerce, hundreds of thousands of users, tens of thousands of daily active users, dozens of people behind the hundreds of people behind the team in support of development, a single system is not suitable.

For example, there is a need to place an order to buy something, which needs to be processed by order system, inventory system, warehouse system and points system. As shown below:

Order systems, inventory systems, warehousing and points systems are all deployed on different machines.

When the user places an order, the order service will send the fastener inventory, notify the warehousing system to deliver the goods, and notify the points system to accumulate points.

If we need to use Spring Cloud to build a distributed architecture at this time, what do we need? What is everything for?

If you use Spring Cloud to implement it, what components are required? Eureka

First of all, we need a registry Eureka, which is mainly responsible for the registration and discovery of each service.

There is an Euraka client component in each microservice, which is responsible for registering the service id (serviceId), ip, port, and other information of the service with Eureka server.

Euraka Server is a registry, which maintains a registry that holds information such as the machine ip and port number on which each service resides.

Feign

Secondly, each service also needs a remote service invocation component Feign, which is mainly responsible for establishing connections with other services, constructing requests, and then initiating requests to invoke other services to obtain data.

Ribbon

Then we may deploy many machines for a service, so when we use Feign to invoke the service, which machine do we send the request to? At this point, we need a component to select a machine according to a certain strategy. No matter how you choose, you just have to choose a machine for Feign to call.

This component is Ribbon,Ribbon, which is mainly responsible for load balancing. Ribbon regularly pulls the registry from the Eureka registry and caches it locally. Each time Ribbon initiates a remote call, Ribbon selects a machine from the data pulled from the Eureka registry and asks Feign to initiate the remote call.

Zuul

For so many micro-services, if there is one IP for each service, do we need to know the IP address of each service if the user needs to call it? How much you have to remember? it's hard to manage.

If you have a unified address, then forward how much to me according to different request paths, for example, / user/* is forwarded to user services, / product/* is forwarded to commodity services, and so on. When I use it, I only need to access the same IP, but the path is different, and that's fine.

Spring Cloud also provides us with a component, which is Zuul, which is a gateway, which is responsible for routing the network. Every request goes through this gateway, and we can also do unified authentication and many other things.

Hystrix

One more thing to say is Hystrix, which is a framework for isolation, circuit breakers, and downgrades.

In the process of mutual invocation of micro-services, there may be called service errors or timeouts, resulting in the collapse and unavailability of the whole system, that is, the service avalanche problem that we often talk about. The existence of Hystrix is to solve this problem.

Overall architecture

Let's follow the process of issuing orders according to the components used above:

The entire invocation process:

First of all, each service needs to register with the registry when it is started.

The user first initiates an order request to the gateway. After receiving the request, the gateway finds that, er, it is an order operation to be sent to the order system, and then the request is routed to the order system.

Order system patter operation, and then through the Feign to call the inventory system to reduce inventory, notify the warehousing service delivery, call the points system to add points.

Before initiating the call, the order system has to go to the registry through Ribbon to pull the registry information of each system, and pick a machine to Feign to initiate the network call.

After reading the above, have you mastered the core architecture principles of Spring Cloud? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

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

Internet Technology

Wechat

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

12
Report