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 are the advantages and disadvantages of Spring Cloud

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

Share

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

This article introduces the relevant knowledge of "what are the advantages and disadvantages of Spring Cloud". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Why do you need to learn Spring Cloud

Whether it is a commercial application or a user application, it is very simple at the beginning of the business, and we usually implement it as a single structure application. However, with the gradual development of the business, the product idea will become more and more complex, and the application of monomer structure will become more and more complex. This will bring the following problems to the application:

* * chaotic code structure: * * the business is complex, resulting in a large amount of code, which makes it more and more difficult to manage. At the same time, it will also bring great challenges to the rapid iteration of the business.

* * inefficient development: * * developers develop a set of code at the same time, so it is difficult to avoid code conflicts. The development process will be accompanied by the process of constantly resolving conflicts, which will seriously affect the efficiency of development.

* * it is expensive to troubleshoot and solve problems: * * online businesses find bug, and the process of repairing bug may be very simple. However, because there is only one set of code, it needs to be recompiled, packaged, and online, which is very expensive.

As the application of monomer structure increases with the increase of system complexity, a variety of problems will be exposed. In recent years, the micro-service architecture has gradually replaced the single architecture, and this trend will become more and more popular. Spring Cloud is the most commonly used micro-service development framework at present, and it has been widely used in enterprise development.

What is Spring Cloud?

Spring Cloud is an ordered collection of frameworks. It makes use of the development convenience of Spring Boot to skillfully simplify the development of distributed system infrastructure, such as service discovery registration, configuration center, intelligent routing, message bus, load balancing, circuit breaker, data monitoring and so on. Spring Boot development style can be used to do one-click startup and deployment.

Spring Cloud does not repeat manufacturing wheels, it just combines the more mature service frameworks developed by various companies and withstands the actual test, and shields the complex configuration and implementation principles through Spring Boot style re-encapsulation, and finally leaves a set of distributed system development toolkits that are easy to understand, easy to deploy and easy to maintain for developers.

Design objectives, advantages and disadvantages

Coordinate various micro-services to simplify distributed system development.

Advantages and disadvantages

There are so many frameworks for microservices, such as dubbo and Kubernetes, why use Spring Cloud?

Advantages:

Produced in the Spring family, Spring is unbeatable in the enterprise development framework, and its origin is very large, which can ensure subsequent updates and improvements.

The components are rich and the functions are complete. Spring Cloud provides very complete support for the microservice architecture. For example, configuration management, service discovery, circuit breakers, micro-service gateways, etc.

The Spring Cloud community is very active and rich in tutorials, so it is easy to find solutions to problems.

The granularity of service splitting is finer and the degree of coupling is relatively low, which is conducive to the reuse of resources and improve the efficiency of development.

The optimized service scheme can be formulated more accurately and the maintainability of the system can be improved.

Reduce the cost of the team, you can develop in parallel, do not pay attention to how others develop, first pay attention to your own development

Microservices can be cross-platform and can be developed in any language.

Suitable for the Internet era, the product iteration cycle is shorter.

Disadvantages:

Too many micro-services and high governance costs are not conducive to the maintenance of the system.

The high cost of distributed system development (fault tolerance, distributed transactions, etc.) is a great challenge to the team.

Generally speaking, the advantages outweigh the disadvantages. At present, Spring Cloud is a very perfect distributed framework. At present, many enterprises begin to use micro-services, and the advantages of Spring Cloud are obvious. Therefore, for students who want to study micro-service architecture, learning Spring Cloud is a good choice.

The development prospect of Spring Cloud

Spring Cloud is a boon for small and medium-sized Internet companies, because such companies often do not have the strength or sufficient capital to develop their own distributed system infrastructure, and using Spring Cloud one-stop solutions can greatly reduce development costs while dealing with business development calmly.

At the same time, with the popularity of micro-service architecture and Docker container concept in recent years, Spring Cloud will have a place in the more and more "cloud" software development style neutrality in the future, especially in a variety of distributed solutions to provide standardized, full-station technical solutions, the significance may be comparable to the birth of Servlet specifications, effectively promote the progress of server software system technology.

Overall architecture

Major project

The subprojects of Spring Cloud can be roughly divided into two categories, one is the encapsulation and abstraction of the existing mature framework "Spring Boot", but also the largest number of projects; the second is the development of a part of the distributed system infrastructure implementation, such as Spring Cloud Stream plays the role of kafka, ActiveMQ.

Spring Cloud Config

Centralized configuration management tool, unified external configuration management in distributed system, default use Git to store configuration, can support client configuration refresh and encryption, decryption operations.

Spring Cloud Netflix

Netflix OSS open source component integration, including Eureka, Hystrix, Ribbon, Feign, Zuul and other core components.

Eureka: a service governance component, including a server-side registry and a client-side service discovery mechanism

Ribbon: service invocation component of load balancer, with multiple load balancer invocation strategies

Hystrix: a service fault-tolerant component that implements the circuit breaker pattern and provides fault tolerance for errors and delays that depend on services

Feign: a declarative service invocation component based on Ribbon and Hystrix

Zuul:API gateway component, which provides routing and filtering functions for requests.

Spring Cloud Bus

The message bus used to propagate cluster state changes can be used to dynamically refresh the service configuration in the cluster by using lightweight message agents to link nodes in the distributed system.

Spring Cloud Consul

Hashicorp Consul-based service governance component.

Spring Cloud Security

Security toolkit, which supports load balancing OAuth3 client and login authentication in Zuul agent.

Spring Cloud Sleuth

Distributed request link tracing for Spring Cloud applications, supporting the use of Zipkin, HTrace, and log-based tracing such as ELK.

Spring Cloud Stream

The lightweight event-driven micro-service framework can use a simple declarative model to send and receive messages, mainly implemented as Apache Kafka and RabbitMQ.

Spring Cloud Task

Used to quickly build a micro-service framework for short, limited data processing tasks to add functional and non-functional features to applications.

Spring Cloud Zookeeper

Apache Zookeeper-based service governance component.

Spring Cloud Gateway

API gateway component, which provides routing and filtering functions for requests.

Spring Cloud OpenFeign

Declarative service invocation components based on Ribbon and Hystrix can dynamically create interface implementations based on Spring MVC annotations for service invocation, which has replaced Feign as a first-class citizen in Spring Cloud 2.0.

Version relationship of Spring Cloud

Spring Cloud is a comprehensive project made up of many sub-projects, each of which has a different release rhythm. To manage the version dependencies of Spring Cloud on each subproject, a list is released that includes the version of the subproject corresponding to a Spring Cloud version.

To avoid confusion between the Spring Cloud version number and the subproject version number, the Spring Cloud version uses the name rather than the version number. The names of these versions take the name of the London subway station and correspond to the chronological order of the version according to alphabetical order, for example, Angel is the first version and Brixton is the second version.

When the Spring Cloud release accumulates to a critical point or a major BUG is resolved, a "service releases" version, or SRX version for short, will be released. For example, Greenwich.SR2 is the second SRX version of the Greenwich version released by Spring Cloud. Currently, the latest version of Spring Cloud is Hoxton.

Spring Cloud and SpringBoot version correspondence

The corresponding relationship between Spring Cloud and each sub-project version

Note: the Hoxton version is based on SpringBoot version 2.2.x and is not applicable to version 1.5.x. As SpringBoot version 1.5.x stops maintenance in August 2019, so will the Edgware version.

The difference between SpringBoot and SpringCloud?

SpringBoot focuses on the rapid and convenient development of individual micro-services.

SpringCloud is a global micro-service coordination governance framework, which integrates and manages individual micro-services developed by SpringBoot.

Provide integrated services such as configuration management, service discovery, circuit breakers, routing, micro-agents, event buses, global locks, decision campaigns, distributed sessions, etc., between microservices.

SpringBoot can use the development project independently without SpringCloud, but SpringCloud can not be separated from SpringBoot and belongs to the dependency relationship.

SpringBoot focuses on the rapid and convenient development of individual micro-services, while SpringCloud focuses on the global service governance framework.

When using Spring Boot to develop distributed microservices, we are faced with the following problems

(1) complexity associated with distributed systems-this overhead includes network problems, delay overhead, bandwidth problems, and security issues.

(2) Service Discovery-the service discovery tool manages how processes and services in the cluster find and talk to each other. It involves a service directory in which services are registered, and then you can find and connect to services in that directory.

(3) redundancy-redundancy in distributed systems.

Load balancing-load balancing improves the distribution of workloads across multiple computing resources, such as computers, computer clusters, network links, central processing units, or disk drives.

(5) performance-performance problems caused by various operational overhead.

(6) deployment complexity-requirements for Devops skills.

What does service registration and discovery mean? How to implement Spring Cloud?

When we start a project, we usually do all the configuration in the properties file. As more and more services are developed and deployed, adding and modifying these properties becomes more complex. Some services may decline, while some locations may change. Manually changing properties can cause problems.

Eureka service registration and discovery can help in this case. Because all services are registered on the Eureka server and lookup is done by calling the Eureka server, there is no need to handle any changes and processing of the service location.

The difference between Spring Cloud and dubbo?

(1) the service invocation method dubbo is RPC springcloud Rest Api

(2) Registration center, dubbo is zookeeper springcloud, it is eureka, it can also be zookeeper

(3) Service gateway, dubbo itself is not implemented, can only be integrated through other third-party technologies, springcloud has Zuul routing gateway, as a routing server for consumer request distribution, springcloud supports circuit breakers, perfectly integrated with git configuration files support version control, transaction bus to achieve configuration file update and service automatic assembly and so on a series of micro-service architecture elements.

What is the significance of load balancing?

In computing, load balancing can improve workload distribution across a variety of computing resources, such as computers, computer clusters, network links, central processing units or disk drives. Load balancing is designed to optimize resource usage, maximize throughput, minimize response time, and avoid overloading any single resource. Using multiple components for load balancing rather than a single component may improve reliability and availability through redundancy. Load balancing usually involves specialized software or hardware, such as multilayer switches or domain name system server processes.

What is Hystrix? How does it achieve fault tolerance?

Hystrix is a delay and fault-tolerant library designed to isolate access points of remote systems, services and third-party libraries, stop cascading failures and achieve resilience in complex distributed systems when failures are inevitable.

Usually for systems developed using micro-service architecture, many micro-services are involved. These microservices collaborate with each other.

Think about the following microservices

Suppose that if the microservice 9 in the figure above fails, then using the traditional method we will propagate an exception. But this can still cause the whole system to crash.

With the increase in the number of microservices, the problem becomes more complicated. The number of microservices can be as high as 1000. This is where hystrix appears and we will use the Fallback method functionality of Hystrix in this case. We have two services employee-consumer that use services exposed by employee-consumer.

The simplified figure is as follows

Now suppose that for some reason, the service exposed by employee-producer throws an exception. We define a fallback method using Hystrix in this case. This fallback method should have the same return type as the exposed service. If an exception occurs in the exposure service, the fallback method returns some values. [

] (http://mp.weixin.qq.com/s?__biz=MzIyNDU2ODA4OQ==&mid=2247485351&idx=2&sn=214225ab4345f4d9c562900cb42a52ba&chksm=e80db1d1df7a38c741137246bf020a5f8970f74cd03530ccc4cb2258c1ced68e66e600e9e059&scene=21#wechat_redirect)

What is a Hystrix circuit breaker? Do we need it?

For some reason, employee-consumer exposes a service that throws an exception. Using Hystrix in this case, we define a fallback method. If an exception occurs in the exposed service, the fallback method returns some default values.

If the exception in firstPage method () continues, the Hystrix circuit will break and the employee user will skip the firtsPage method together and call the fallback method directly. The purpose of the circuit breaker is to allow time for the first page method or other methods that may be called by the first page method, and to cause an abnormal recovery. What may happen is that the problem that causes the exception has a better chance of recovery when the load is low.

What is Netflix Feign? What are its advantages?

Feign is a java client binder inspired by Retrofit,JAXRS-2.0 and WebSocket.

The first goal of Feign is to unify the complexity of the constraint denominator to http apis, regardless of its stability.

In the case of employee-consumer, we use the REST service that employee-producer exposes using the REST template.

But we have to write a lot of code to perform the following steps

(1) use the ribbon for load balancing.

(2) get the service instance, and then get the basic URL.

(3) use the REST template to use the service. The previous code is as follows

@ Controllerpublic class ConsumerControllerClient {@ Autowiredprivate LoadBalancerClient loadBalancer;public void getEmployee () throws RestClientException, IOException {ServiceInstance serviceInstance=loadBalancer.choose ("employee-producer"); System.out.println (serviceInstance.getUri ()); String baseUrl=serviceInstance.getUri (). ToString (); baseUrl=baseUrl+ "/ employee"; RestTemplate restTemplate = new RestTemplate (); ResponseEntity response=null; try {response=restTemplate.exchange (baseUrl, HttpMethod.GET, getHeaders (), String.class);} catch (Exception ex) {System.out.println (ex);} System.out.println (response.getBody ());}

Previous code, with exceptions like NullPointer, was not optimal. We'll see how to use Netflix Feign to make calls easier and cleaner. If the Netflix Ribbon dependency is also in the classpath, then Feign is also responsible for load balancing by default.

What is Spring Cloud Bus? Do we need it?

Consider the following situation: we have multiple applications that use Spring Cloud Config to read properties, and Spring Cloud Config reads these properties from GIT.

In the following example, multiple employee producer modules obtain Eureka registered property from Employee Config Module.

What happens if the Eureka registration property in GIT changes to point to another Eureka server. In this case, we will have to restart the service to get the updated properties.

There is another way to use the actuator endpoint / refresh. But we will have to call this url separately for each module. For example, if Employee Producer1 is deployed on port 8080, http:// localhost:8080 / refresh is called. Also for Employee Producer2 http://localhost:8081 / refresh and so on. This is troublesome again. This is where Spring Cloud Bus plays a role.

Spring Cloud Bus provides the ability to refresh configurations across multiple instances. Therefore, in the above example, if we refresh the Employee Producer1, we will automatically refresh all other necessary modules. This is especially useful if we have multiple microservices up and running. This is achieved by connecting all microservices to a single message broker. Whenever the instance is refreshed, this event subscribes to all microservices that listen on the agent, and they are refreshed as well. You can refresh any single instance by using endpoint / bus / refresh. [

] (http://mp.weixin.qq.com/s?__biz=MzIyNDU2ODA4OQ==&mid=2247485351&idx=2&sn=214225ab4345f4d9c562900cb42a52ba&chksm=e80db1d1df7a38c741137246bf020a5f8970f74cd03530ccc4cb2258c1ced68e66e600e9e059&scene=21#wechat_redirect)

The function of Spring Cloud Circuit Breaker

When one service invokes another service due to network reasons or its own reasons, the caller will wait for the callee's response when more service requests to these resources lead to more requests waiting, resulting in a knock-on effect (avalanche effect)

The circuit breaker is fully open: it cannot be called for a certain number of times over a period of time and monitors several times that the circuit breaker is fully open with no signs of recovery so that the service will not be requested for the next request.

Half open: there are signs of recovery in a short period of time, the circuit breaker will send part of the request to the service, and the circuit breaker will shut down when it is called normally.

Shutdown: when the service has been in a normal state, it can be called normally

What is Spring Cloud Config?

In the distributed system, due to the large number of services, in order to facilitate the unified management of service configuration files and real-time update, distributed configuration center components are needed. In Spring Cloud, there is a distributed configuration center component, spring cloud config, which allows configuration services to be placed in memory (that is, locally) of configuration services, as well as in remote Git repositories. In the spring cloud config component, there are two roles, one is config server, and the other is config client.

Use:

(1) add pom dependency

(2) add relevant configurations to the configuration file

(3) add annotation @ EnableConfigServer to the startup class

What is Spring Cloud Gateway?

Spring Cloud Gateway is the second generation gateway framework officially launched by Spring Cloud, replacing the Zuul gateway. As a kind of traffic, gateway plays a very important role in micro-service system. The common functions of gateway are routing and forwarding, authority verification, current limiting control and so on.

Use a RouteLocatorBuilder bean to create a route, in addition to creating a route RouteLocatorBuilder allows you to add a variety of predicates and filters,predicates assertions, as the name implies, according to the specific request rules, by the specific route to deal with, filters is a variety of filters, used to make various judgments and modifications to the request.

This is the end of "what are the advantages and disadvantages of Spring Cloud". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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