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 basics of Spring Cloud

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the relevant knowledge of "what are the basic knowledge of Spring Cloud". In the operation of actual cases, many people will encounter such a dilemma. Then 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!

Spring Cloud's "born from a distinguished family"

As the most popular micro-service framework at present, the name of Spring Cloud can be said to be unknown to everyone. With the good mass base of Spring Framework and the contemporary name Cloud, Spring Cloud has been recognized by everyone as soon as it appears.

The mention of Spring Cloud is reminiscent of Spring Boot, which has just released version 2.0. Spring Boot and Spring Cloud are both from Pivotal. Although Spring Boot and Spring Cloud are hot, there are not many people who know Pivotal in China. In fact, Pivotal has made some achievements in cloud computing, big data, virtualization and other fields. Here is a brief gossip about Pivotal.

Pivotal is a company jointly established by EMC and VMware. GE (General Electric) also acquired a stake in Pivotal. At the same time, GE is also an important customer of Pivotal. In addition to Spring Framework, Spring Boot and Spring Cloud, Reids, RabbitMQ, Greenplum, Gemfire and Cloud Foundry, which are often used in our daily development, are all products belonging to Pivotal. Among them, Gemfire is also a distributed memory database used by China Railway Corporation 12306, which means that if you can't buy a train ticket when you come home for the Spring Festival, the Gemfire of this pot Pivotal will also be memorized (a little joke, ).

"getting started" of Spring Cloud

As a micro-service development framework, Spring Cloud includes many components, including: Spring Cloud Netflix (Eureka, Hystrix, Zuul, Archaius), Spring Cloud Config, Spring Cloud Bus, Spring Cloud Cluster, Spring Cloud Consul, Spring Cloud Security, Spring Cloud Sleuth, Spring Cloud Data Flow, Spring Cloud Stream, Spring Cloud Task, Spring Cloud Zookeeper, Spring Cloud Connectors, Spring Cloud Starters, Spring Cloud CLI and so on.

Among the above components, Spring Cloud Netflix is the core framework of micro-services, which is open source by Internet streaming media player Netflix and incorporated into the Spring Cloud family. It provides the most basic functions of micro-services: service discovery (Service Discovery), dynamic routing (Dynamic Routing), load balancing (Load Balancing), and edge server (Edge Server).

Spring Boot is a set of quick configuration scaffolding from Spring that can quickly develop individual micro services based on Spring Boot. Spring Boot simplifies Spring-based application development, creating an independent, production-level Spring application with a small amount of code. Because Spring Cloud is based on Spring Boot development, you must use Spring Boot to use Spring Cloud.

The following figure is a common architectural diagram of Spring Cloud. The following figure is an example of a brief introduction to some of the most commonly used components of Spring Cloud:

L Eureka: service registry, a REST-based service for locating services to enable service discovery and failover in microservice architectures.

L Hystrix: fuses, fault-tolerant management tools designed to control the nodes of services and third-party libraries through fuse mechanisms, thereby providing greater fault tolerance for delays and failures.

L Turbine:Turbine is a tool for the aggregation server to send event flow data, which is used to monitor the Metrics of Hystrix under the cluster.

L Zuul:API gateway, Zuul is a framework that provides edge services such as dynamic routing, monitoring, elasticity, security and so on.

L Ribbon: provides load balancing in microservices. There are a variety of load balancing strategies to choose from, which can be used with service discovery and circuit breakers.

L Feign:Feign is a declarative, templated HTTP client.

L Spring Cloud Config: configuration management toolkit that allows you to put configurations on remote servers and centrally manage cluster configurations, currently supporting local storage, Git, and Subversion.

L Spring Cloud Security: a Spring Security-based security toolkit that adds security controls for microservice applications.

L SpringCloud Sleuth: log collection toolkit, which encapsulates Dapper and log-based tracking as well as Zipkin and HTrace operations, and implements a distributed tracking solution for SpringCloud applications.

In addition to the basic components described above, there are a variety of common Spring Cloud components, involving all aspects of micro services and application development:

L Spring Cloud Starters:Spring Boot-style startup project that provides out-of-the-box dependency management for Spring Cloud.

L Archaius: configuration management API, including a series of configuration management API, providing dynamic typed properties, thread-safe configuration operations, polling framework, callback mechanism and other functions.

L Consul: encapsulates Consul operations. Consul is a service discovery and configuration tool that integrates seamlessly with Docker containers.

L Spring Cloud Stream: data flow operation development kit that encapsulates sending and receiving messages with Redis,Rabbit, Kafka, etc.

L Spring Cloud CLI: based on Spring Boot CLI, it allows you to quickly build cloud components on the command line.

L Spring Cloud Task: provide cloud planning task management and task scheduling.

L Spring Cloud Bus: event, message bus, used to propagate state changes in a cluster (for example, configuration change events) and can be hot deployed in conjunction with Spring Cloud Config.

L Spring Cloud Data Flow: big data operating tool, as an alternative to Spring XD, it is a hybrid computing model that combines streaming data with batch data processing.

L Spring Cloud Zookeeper: a toolkit for operating Zookeeper for service discovery and configuration management using zookeeper.

L Spring Cloud Connectors: makes it easy for cloud applications to connect to the back end on various PaaS platforms, such as database and message broker services.

Spring Cloud's "mastery"

Although Spring Cloud integrates many components to build a complete micro-service application, each component is not perfect, and many components have many shortcomings and defects in practical applications. Therefore, we need to replace and modify some of these components in order to build a powerful, flexible and robust micro-service architecture application.

L configuration Center:

Spring Cloud Config can be said to be the most Low component in the Spring Cloud family, directly using local storage / SVN/Git storage. At the same time, Spring Cloud Config also lacks a complete visual management query background, when there are more complex rights management and version management requirements, Spring Cloud Config will appear to be very inadequate. If you need to push configuration information automatically after configuration modification, the use of Spring Cloud Config can not meet the requirements, so you need to write your own code to implement it.

At present, there are many open source configuration center implementation schemes in the open source community, and many companies have developed their own configuration center solutions. Including Taobao unified configuration center Diamond (which has not been updated for many years), Baidu's distributed configuration management platform Disconf, Ctrip's open source distributed configuration center Apollo, 360 distributed configuration management tool QConf and so on. At present, the author's company adopts the configuration center developed by our own company, and the main reason for not adopting open source implementation is that we need to adapt to multiple scenarios such as Spring Cloud and Dubbo at the same time.

L registration center

As the service registry of Spring Cloud, according to the theory of distributed CAP, Eureka adopts AP-type design, which emphasizes the high availability of the registry. Compared with Zookeeper, the service registry commonly used by Dubbo, Zookeeper adopts CP design, which emphasizes the consistency of registry data.

Eureka is designed to be simple and easy to use, but there is no persistence of registry data by default. At the same time, in extreme scenarios, there will be data inconsistencies among multiple Eureka registry nodes, or even loss of service registration data. Of course, from the perspective of distributed CAP theory, it is theoretically impossible to take into account the three points of CAP at the same time. At present, some Internet companies have modified Eureka to support the persistence of data, but they can not fully support all the requirements of CAP.

L API Gateway

API gateway can be said to be the most demanding and difficult component of micro-services. It should be said that the Zuul integrated in Spring Cloud implements the routing function of services, and other functions such as load balancing need to be combined with components such as Ribbon. For many personalized requirements, developers need to code and implement by themselves.

Like most Java-based Web applications, Zuul also uses the Servlet architecture, so Zuul handles each request by using a thread for each request. At the same time, because Zuul is based on JVM implementation, performance will also become a bottleneck in high concurrent access scenarios. Although some online articles evaluate the performance of Zuul and Nginx are similar, but in the scenario with high performance requirements, the memory management and garbage collection of JVM is still a big problem. So in the actual application scenario, it is usually used to add a layer of Nginx or OpenResty before the points of multiple Zuul to act as a proxy.

In order to solve the performance problem of Zuul, Netflix upgrades its gateway service Zuul. The new Zuul 2 changes the processing of HTTP requests from synchronous to asynchronous, and adds functions such as HTTP/2, websocket and so on. But unfortunately, the open source version of Zuul 2 has been in a difficult state and has never been officially seen with you.

L fuse

There are various requirements for current limiting, degradation and circuit breaker in micro-services, which need to be controlled in the API gateway and each specific service interface in order to meet the application needs of micro-service architecture in complex scenarios.

Using Hystrix in Spring Cloud alone can not fully meet the above complex requirements. It is necessary to combine API gateway and provide isolation to resources, processes and namespaces through Kubernetes, and to achieve current limiting, downgrade, circuit breaker and other requirements for all services through some custom coding.

L monitoring system

Whether it is the integrated Spring Cloud Sleuth in Spring Cloud or the integrated classic ELK, it is only tracking and monitoring at the log level. In large and medium-sized micro-service application architectures, especially JVM-based projects, we also need to add APM monitoring mechanism to ensure that a variety of potential performance problems are found in a timely manner.

On the whole, APM mainly completes three functions: 1. Log tracking, 2. Monitoring and alarm, 3. Performance statistics. At present, there are many commercial versions of APM at home and abroad, and the open source versions of APM are also beginning to enrich. The main open source APM schemes in China are: CAT by Dianping and SkyWalking in Apache incubation. Here, we mainly recommend that SkyWalking,SkyWalking is an application performance monitoring system for distributed systems, especially for micro-services, Cloud Native and containerized (Docker, Kubernetes, Mesos) architectures. The attention and development of the project are very fast, and the Chinese documentation is also relatively complete.

Spring Cloud's "giving up"

Spring Cloud can be said to be a perfect micro-service entry framework, if you are in a small and medium-sized project to apply Spring Cloud, then you do not need much modification and adaptation, you can achieve the basic functions of micro-services. However, if you are practicing micro-services in large-scale projects, you may find that there are still many problems to deal with, especially if there is so much old code in the project that you cannot upgrade all of them directly to the Spring Boot framework for development, you will very much want to have a less intrusive solution to implement the micro-service architecture. In this scenario, Service Mesh will be your best choice. After a period of development, the concept of Service Mesh has been gradually understood and recognized by everyone. At the same time, some Service Mesh implementation schemes have gradually matured and landed, such as Istio, Linkerd, Envoy and so on. The next article in this series will give you a systematic introduction to the concept of Service Mesh. However, before understanding the concept of Service Mesh, it is recommended that you first have an in-depth understanding of the concepts and frameworks of micro-services and Spring Cloud, so that you can realize the value and significance of applying Service Mesh.

Spring Cloud and Dubbo

There are many articles on the Internet about the comparison between Spring Cloud and Dubbo, and most of the comparisons show that Spring Cloud has an overwhelming advantage over Dubbo. The following table is a comparison of a basic function of Dubbo and Spring Cloud:

Dubbo

Spring Cloud

Registration center

Zookeeper

Spring Cloud Eureka

Service invocation mode

RPC

Restful API

Service gateway

None

Spring Cloud Zuul

Demotion and fusing

Only demotion, no fuse.

Spring Cloud Hystrix

Configuration center

None

Spring Cloud Config

Service tracking

Dubbo-admin

& Dubbo-monitor

Spring Cloud Sleuth

Message bus

None

Spring Cloud Bus

Data stream

None

Spring Cloud Stream

Batch task

None

Spring Cloud Task

In fact, Dubbo's focus is on service governance, which is not a true micro-service framework. Including Dubbo 3.0, which is currently under development, can not fully cover the functional requirements of microservices. On the one hand, Spring Cloud is designed for micro-services, on the other hand, Spring Cloud implements micro-services by integrating various components, so in theory, most of the micro-service-related components in the industry can be integrated to achieve all the functions of micro-services.

As for Dubbo, if it must be applied to the usage scenario of micro-services, most of the functions lacking in the above table can be realized by integrating third-party applications and components. Compared with Spring Cloud, the main drawback lies in the convenience and compatibility in the integration process.

Spring Cloud and Docker

Although there are many articles on the Internet about how to use Docker to implement micro-services, in fact, it is impossible to use Docker alone to achieve all the functions of micro-services. In fact, in micro-service architecture, Spring Cloud and Docker are more of a collaborative relationship than a competitive relationship. Through Docker containerization technology, we can better solve the complexity of deployment and operation and maintenance brought by the introduction of Spring Cloud micro-services.

Pivotal Cloud Foundry (PCF) in the Spring Cloud ecosystem, as a PAAS implementation, also provides some functional support similar to Docker, but it is still quite different from Docker in terms of function and ease of use. The relationship between Pivotal Cloud Foundry and Docker is more compatible than competitive. The main competitor of Pivotal Cloud Foundry is Red Hat's OpenShift. Currently, IAAS supported by Pivotal Cloud Foundry includes: AWS, AZURE, GCP, vSphere, OpenStack and so on.

Spring Cloud and Kubernetes

There are also some articles on the Internet, such as "which is better, Spring Cloud or Kubernetes" and "do you need to use Spring Cloud when you already have Kubernetes?" First of all, the author does not think that Spring Cloud and Kubernetes are competitive, but does not deny that there is some overlap between them in many functions. The following figure is a comparison of some of the basic functions of Spring Cloud and Kubernetes in the micro-services architecture.

Kubernetes

Spring Cloud

Registration center

Kubernetes Service

& Ingress Resource

Spring Cloud Eureka

Configuration center

Kubernetes ConfigMap

& Secrets

Spring Cloud Config

Service gateway

Kubernetes Service

& Ingress Resource

Spring Cloud Zuul

Demotion and fusing

Kubernetes Health Check

& Resource Isolation

Spring Cloud Hystrix

Load balancing

Kubernetes Service

Spring Cloud Ribbon

Service tracking

OpenTracing

Spring Cloud Sleuth

Service security

None

Spring Cloud Security

Packaged deployment

Kubernetes Scheduler

& Deployment

Spring Boot

Task work management

Kubernetes Jobs

& Scheduled Jobs

Spring Batch

By comparison, we can see that there is some functional overlap between Spring Cloud and Kubernetes, but the positioning of the two is actually very different. Spring Cloud is a micro-service development framework based on Java language, while Kubernetes is an open source system for automatic deployment, scaling and management of container applications. It is compatible with multiple languages and provides primitives for creating, running, scaling and managing distributed systems. Spring Cloud is more aimed at Java language developers with Spring development experience, while Kubernetes is not a platform for developers, it is intended for IT people with DevOps ideas.

To distinguish the scope of the Spring Cloud and Kubernetes projects, the following figure lists almost end-to-end micro-service architecture requirements, from the bottom hardware to the top DevOps and self-service experience, and lists how to relate to the Spring Cloud and Kubernetes platforms.

This is the end of the content of "what are the basics of Spring Cloud". Thank you for 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

Servers

Wechat

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

12
Report