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 the SpringCloud framework

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

Share

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

This article mainly introduces "how to understand the SpringCloud framework". In daily operation, I believe many people have doubts about how to understand the SpringCloud framework. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "how to understand the SpringCloud framework"! Next, please follow the editor to study!

This article is based on SpringBoot 1.5.7 and SpirngCloud Dalston.SR5.

For this architecture diagram, I would like to introduce this layer by layer:

1. It is the choice of web server. Nginx+keepalived,haproxy is also a choice, but haproxy has a lot of problems when reverse proxy handles cross-domain access. So we do keep-alive mode processing in some places in nginx, which reduces the number of three-way handshakes and improves the connection efficiency. Keepalived does the load of nginx, a virtual vip is external, two nginx are highly available, and nginx itself is a reverse proxy for the zuul cluster.

2. Api gateway. Many people criticize zuul here, saying that it is recommended to use nginx directly because of its slow speed. I still recommend using zuul here. After all, zuul contains interceptors and reverse proxies, which are very useful in rights management, single sign-on and user authentication. Moreover, zuul comes with ribbon load balancing. If you directly use nginx, you need to do a separate feign or ribbon layer to do the load layer of the business cluster. After all, it is too dangerous to expose the interface directly to the web server. Here zuul comes with ribbon load balancer and hystrix circuit breaker. Direct reverse proxy serviceId can proxy the entire cluster.

3. Business cluster, some of my projects in this layer are divided into two layers, that is, a load layer is added above, the bottom layer starts from service, and the bottom layer is only a simple interface. Controller is a separate layer implemented by feign, and then internal different business service interfaces are tuned to call the controller layer directly. It can only be said that the effect is mediocre, with one more tcp connection. Therefore, I recommend merging, because anyone who has done spring cloud projects knows that feign contains ribbon, and zuul also contains ribbon, so that zuul invokes the service cluster and the intermodulation of interfaces between the service cluster is highly available, ensuring the stability of communication. Hystrix is still necessary, it is difficult to achieve service degradation without circuit breakers, and there will be a large number of requests sent to unavailable nodes. Of course, service can be modified. If it is transformed into rpc mode, the intermodulation between services will be another situation. It will be in the form of load pool and interface service pool. Load pool calls interface pool, interface pool calls each other rpc. Feign client only achieves the form of imitating rpc by implementing the interface, but the speed performance is still good.

4. Redis cache pool, which is used for session sharing, distributed system session sharing is a big problem. At the same time, it is very helpful for redis to do secondary cache to reduce the response time of the whole service and reduce the number of database visits. Of course, redis cluster or redis sentinel chooses.

5. Eurake registry is a highly available cluster. There are many details here, such as how often the list is refreshed and how often the heartbeat is monitored.

6, spring admin, this is very recommended, this function is very powerful, you can integrate turbine circuit breaker monitor, and you can define the log level of all classes, do not have to configure separately, you can also view local log log files, monitor machine parameters and performance of different services, very powerful. It is coupled with elk dynamic log collection system, which is very convenient for project operation and maintenance.

7. Zipkin, which can be viewed directly in its own functional interface or in the form of stream streams, collected by the elk dynamic logging system. But I have to say that this is very harmful to the performance of the system, because link tracking will cause a response wait, and the waiting time is very long and close to 1 second, which is unbearable in the production environment, so it is best to turn it off in the production environment and turn it on when there is a problem debugging.

8, message queue, this must, distributed system can not all scenarios meet strong consistency, here can only be used by message queue as a buffer, here I use Kafka.

9. Distributed things, which I think is the most difficult, because different business clusters correspond to their own databases, which are not interoperable, and mutual service calls can only interface with each other, and some of them are even remote. The result is request waiting caused by network delay and data loss caused by network jitter. These are terrible problems, so we have to deal with distributed things. What I recommend is to use the message queue and adopt the two-phase submission protocol to cooperate with the transaction compensation mechanism. The specific implementation needs to be combined with the business, so there is no need to expand on the limited space here.

10. Config configuration center, which is necessary because there are too many services and too many configuration files, so it is difficult to operate and maintain without this. This generally uses the message queue to establish a spring cloud bus, which stores the configuration file by git, and dynamically updates the configuration file information using the bus bus.

11. In the real-time distributed log system, logstash collects local log file streams and transmits them to elasticsearch,logstash in two ways. 1. Each machine starts a logstash service to read local log files and generate streams to elasticsearch. 2. Logback introduces the logstash package, and then directly produces the json and flows it to a central logstash server, which is then passed to elasticsearch. Elasticsearch then passes the stream to kibana, dynamically views the log, and even the stream of zipkin can be passed directly to elasticsearch. This with spring admin, one view dynamic logs, one view local logs, but also can remotely manage different types of log levels, which is very beneficial to integration and operation and maintenance.

Finally, many things of spring cloud are more accurate, such as circuit breaker trigger time, thing compensation time, http response time and so on, which need to be well designed, and there are many points that can be optimized. For example, http communications can use okhttp,jvm optimization, nio mode, data connection pooling, etc., which can greatly improve performance.

There is also a docker problem. Many people say that without docker, it is not a micro-service. In fact, in my personal opinion, spring cloud itself is a micro-service, which only requires a jdk environment. Writing dockerfile is nothing more than integrating jdk, adding jar packages, executing jar, or using docker compose to combine the image of several different services into a container. But there are many problems, such as communication problems, server performance issues, container process crashes, of course, if you have a mature K8s-based container management platform, this is no problem, if it is not possible to consider. Spring cloud itself is a micro-service distributed architecture, so individuals are recommended to deploy directly on the machine, of course, good DevOps tools will be much more convenient.

Introduction

In the interview, the interviewer likes to ask about the implementation principle of the component, especially the common technology, we usually use SpringCloud also need to understand its implementation principle, which can not only play a role of inference, but also help to easily deal with a variety of problems and targeted expansion.

The following are some of the principles of the course "Java in-depth micro-service principles to transform the real estate sales platform", which are now available to you free of charge, so that you can easily deal with the principle interview questions.

How the service registration discovery component Eureka works

How the Service Gateway component Zuul works

Cross-domain sequence diagram

Working principle of Eureka and Ribbon Integration

Solve distributed consistency

Cascaded failure process

Working principle of circuit breaker assembly Hystrix

Working principle of distributed tracking Sleuth

How SpringBoot Auto configuration works

At this point, the study on "how to understand the SpringCloud framework" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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