Xiaobai easily learns Spring Cloud

Before understanding Spring Cloud, let's have a general understanding of the concept of microservices.

Traditional monolithic architecture

Monolithic architecture is more common in small and micro enterprises. A typical representative is that an application, a database, and a web container can run.

As can be seen from the above figure, the monolithic architecture is basically as mentioned above: an application, a database, and a web container, which integrate all functions. This is easier to maintain in small projects. After all, there are not many functions and are not complicated, but the scalability and reliability are relatively poor, because all functions are integrated in a service or a war package. When modifying a function, you need all Service repackaged. It may be that the development is relatively fast in the early stage, and as the function grows in the later stage, the interaction cycle will become longer and longer.

Service Architecture

Service-oriented architecture can also be called SOA architecture.

SOA stands for service-oriented architecture, which divides applications into different modules according to different responsibilities, and different modules interact directly through specific protocols and interfaces. In this way, the entire system is divided into many individual component services to complete the request. When the traffic is too large, the corresponding components are supported by horizontal expansion. All components interact to meet the overall business needs.

The advantage of SOA as a service is that it can distribute, combine and use loosely coupled coarse-grained application components through the network according to requirements. The service layer is the foundation of SOA, which can be directly invoked by applications, so as to effectively control the artificial dependence of the interaction with software agents in the system.

The service-oriented architecture is a loosely coupled architecture. The principle of splitting services is high cohesion within services and low coupling between services.

Generally, we use dubbo to manage services. Before using SpringCloud, we basically use dubbo to split services and call between services.

Look at the architecture diagram of the service architecture:

It can be found that from the monolithic architecture to the service-oriented architecture, the number of applications is constantly increasing, and the slowly sinking ones become the basic components, and the floating ones become the business systems. It can also be seen from the above that the essence of the architecture is continuous splitting and refactoring: the splitting process is to split the system into various subsystems/modules/components. Divide the boundaries of each other to achieve a reasonable split. Combination is the organic integration of separate components according to the final requirements. The result of splitting enables developers to focus on business and skills, and achieve agile development. The result of integration is that the system becomes flexible and can be changed according to needs, achieving business agility.

In fact, I think the core is the boundary split. How to disassemble and how fine the granularity of dismantling is, it is a test of an architect's control over the business and the underlying technology. A good architect will make the boundaries of the entire system clear and distinct, with little overlapping of functions. (I don’t know when I can grow into an architect (┬_┬))

microservice architecture

To put it simply, the microservice architecture is an extension of the SOA architecture idea, which puts more emphasis on the independence of individual services and smaller split granularity.

The following picture is also on the PPT for the company's internal training last time. I think it can give a good overview of what microservices are:

In fact, the service architecture can already solve the needs of most enterprises, so why should we study microservices?

First talk about their differences;

The microservice architecture emphasizes that the business system needs to be thoroughly componentized and serviced. A component is a product that can provide services independently

Microservice no longer emphasizes the relatively heavy ESB enterprise service bus in the traditional SOA architecture

Microservices emphasize that each microservice has its own independent operating space, including database resources.

The microservice architecture itself comes from the idea of ​​the Internet, so the services published by components emphasize the use of HTTP Rest API

The segmentation granularity of microservices will be smaller

I believe everyone should have seen the picture below. Of course, this picture is only a part. If you are interested, you can take a look at "A Typical Microservice Architecture":

To put it simply, it can be seen from the figure that each application functional area is completed using microservices, which are independent of each other, and communicate with each other through a lightweight communication protocol (Http). According to actual business needs, choose your own technology stack and development language.

Therefore, it can be seen that the advantages of microservices are: service independence, good scalability, and strong reliability, but at the same time, it also faces some new problems, such as operation and maintenance complexity, distributed complexity, monitoring complexity, and so on.

What is Spring Cloud

SpringCloud is a set of frameworks for implementing microservices based on SpringBoot . It provides components such as configuration management, service discovery, circuit breaker, intelligent routing, micro-agent, control bus, global lock, decision-making campaign, distributed session and cluster state management required for microservice development. Most importantly, based on SpringBoot, it will be very convenient to develop microservice architecture.

The official website also gives the positioning and description of Spring Cloud:

 

Since, SpringClud itself is a set of framework and a big housekeeper. The following figure lists some of the more core functions:

SpringCloud itself contains a lot of components, the following is a brief list:

core components

SpringCloudGateway

Spring Cloud Gateway is a gateway developed by Spring based on technologies such as Spring 5.0, Spring Boot 2.0 and Project Reactor. Spring Cloud Gateway aims to provide a simple and effective unified API routing management method for microservice architecture. As the gateway in the Spring Cloud ecosystem, Spring Cloud Gateway aims to replace Netflix ZUUL. It not only provides a unified routing method, but also provides basic functions of the gateway based on the Filter chain, such as: security, monitoring/burying, and limiting flow etc.

SpringCloudNetflix

This is a big boss, second only to the boss. The boss relies on it for various services and integrates with various Netflix OSS components to form the core of microservices. Its younger brothers mainly include Eureka, Hystrix, Zuul... too many

Netflix Eureka

Service Center, Cloud Service Discovery, a REST-based service for locating services to enable cloud middle-tier service discovery and failover. Service center, any younger brother who needs the support of other younger brothers needs to get it from here. Similarly, if you have any unique martial arts, report it as soon as possible, so that other younger brothers can call it in the future; its advantage is that you don’t need to find all kinds of younger brothers directly. Support, you only need to go to the service center to get it, and you don’t need to know where the other brothers who provide support are, or a few brothers come to support, anyway, just use it, the service center ensures stability and quality.

Netflix Hystrix

Fuse, a fault-tolerant management tool, aims to control the nodes of services and third-party libraries through the fuse mechanism, so as to provide stronger fault tolerance for delays and failures. For example, suddenly a little brother is sick, but you still need its support, and then it does not respond for a long time after calling it, but you don’t know it, and you have been waiting for this response; it is possible that other little brothers are also calling your martial arts stunt, then When there are many requests, serious congestion will occur and affect the overall plan of the boss. At this time, Hystrix comes in handy. When Hystrix finds that a certain brother is not in an unstable state, he will immediately let him go offline, let other brothers come to the top, or tell you that there is no need to wait. This boy will definitely not be able to do it today. Why hurry up? Why don't you line up here.

Netflix Zuul

Zuul is a framework that provides edge services such as dynamic routing, monitoring, elasticity, and security on the cloud platform. Zuul acts as the front door for all requests to the device and the web site backend of the Netflix streaming application. When other sects come to ask the eldest brother to do business, they must first pass through Zuul to see if there is a knife or something to intercept and go back, or if they need to find the younger brother, take it directly.

SpringCloudConfig

Commonly known as the configuration center, the configuration management toolkit allows you to put configurations on remote servers and centrally manage cluster configurations. Currently, it supports local storage, Git, and Subversion. That is, in the future, everyone's weapons, guns, and other things will be put together together, so don't bring them casually, so that it will be convenient for unified management and equipment upgrades in the future.

SpringCloudBus

Event, message bus, used to propagate state changes in the cluster (for example, configuration change events), and can be combined with Spring Cloud Config to realize hot deployment. It is equivalent to Dai Zong, the god-walking Taibao who traveled 800 miles a day in the Water Margin, to ensure that the news between the younger brothers remains unimpeded.

SpringCloudforCloudFoundry

Cloud Foundry is the industry's first open source PaaS cloud platform launched by VMware. It supports multiple frameworks, languages, runtime environments, cloud platforms and application services, enabling developers to deploy and expand applications in seconds. No need to worry about any infrastructure issues

In fact, it is a set of solutions integrated with CloudFoundry, which embraces Cloud Foundry's thigh.

SpringCloudCluster

Spring Cloud Cluster will replace Spring Integration. Provides the basic functional support required by clusters in distributed systems, such as the abstraction and implementation of common state modes such as elections, cluster state consistency, global locks, and tokens.

If you organize different gangs into a unified whole, Spring Cloud Cluster has provided you with many convenient tools for organizing them into a unified whole.

SpringCloudConsul

Consul is a service software that supports distributed and highly available service discovery and configuration sharing in multiple data centers. It was developed by HashiCorp in Go language and is open source based on the Mozilla Public License 2.0 protocol. Consul supports health checks and allows HTTP and DNS protocols Call the API to store key-value pairs.

Spring Cloud Consul encapsulates Consul operations. Consul is a service discovery and configuration tool that can be seamlessly integrated with Docker containers.

Subsequent articles will basically explain the use of these components.

other components

Of course, in addition to the above listed, there are also such as Spring Cloud Security, Spring Cloud Sleuth, Spring Cloud Data Flow, Spring Cloud Stream, Spring Cloud Zookeeper and so on.

Spring Cloud Security

Add security controls to your application based on spring security's security toolkit. This little guy is very arrogant and is responsible for the security of the entire gang. He has set up different sects to access specific resources, and he can't leak the cheat book Sunflower Collection.

Spring Cloud Sleuth

The log collection toolkit encapsulates Dapper and log-based tracing as well as Zipkin and HTrace operations, and implements a distributed tracing solution for Spring Cloud applications.

Spring Cloud Data Flow

Dataflow is a unified programming model and managed service for developing and executing large-scale data processing patterns including ETL, batch computing and continuous computing.

Spring Cloud Data Flow is a cloud-native orchestration service for composable microservices in modern runtime environments. Using Spring Cloud Data Flow, developers can create and orchestrate data pipelines for common use cases like data ingestion, real-time analysis, and data import/export.

Spring Cloud data flow is a redesign of spring XD based on the native cloud. The goal of this project is to simplify the development of big data applications. The reconstruction of Spring XD's stream processing and batch processing modules are respectively based on Spring Boot's stream and task/batch microservice programs. These programs are now automated deployment units and they natively support modern runtimes like Cloud Foundry, Apache YARN, Apache Mesos, and Kubernetes.

Spring Cloud data flow provides a series of models and best practices for distributed stream processing and batch processing data channels based on microservices.

Spring Cloud Stream

Spring Cloud Stream is a framework for creating message-driven microservice applications. Spring Cloud Stream is created based on Spring Boot and is used to build a separate/industrial-grade spring application, using spring integration to provide a connection with the message broker. The data flow operation development kit encapsulates sending and receiving messages with Redis, Rabbit, Kafka, etc.

A business involves multiple tasks, and the tasks are triggered by events. This is what Spring Cloud stream will do.

Spring Cloud Task

Spring Cloud Task mainly solves the task management and task scheduling of short-lived microservices. For example, some scheduled tasks run once at night, or a certain data analysis runs several times temporarily.

Spring Cloud Zookeeper

ZooKeeper is a distributed, open source distributed application coordination service, an open source implementation of Google's Chubby, and an important component of Hadoop and Hbase. It is a software that provides consistent services for distributed applications. Its functions include: configuration maintenance, domain name service, distributed synchronization, group service, etc. The goal of ZooKeeper is to encapsulate complex and error-prone key services, and provide users with a simple and easy-to-use interface and a system with high performance and stable functions.

The toolkit for operating Zookeeper is used for service discovery and configuration management using zookeeper, which embraces Zookeeper's thigh.

Spring Cloud Connectors

Spring Cloud Connectors simplifies the process of connecting to services and obtaining operations from the cloud platform. It has strong scalability and can use Spring Cloud Connectors to build your own cloud platform.

It is convenient for cloud applications to connect to the backend on various PaaS platforms, such as: database and message broker services.

Spring Cloud CLI

Based on Spring Boot CLI, it allows you to quickly build cloud components with the command line.

Digression: With so many components, relatively few ⊙﹏⊙‖∣ are currently used. The most commonly used is Netflix's family bucket. The road to learning is long and long!

Why choose Spring Cloud

There are so many microservice frameworks such as: dubbo, why use Spring Cloud?

Produced in the big spring family, spring is unrivaled in the enterprise-level development framework, and has a great background, which can guarantee subsequent updates and improvements.

Having Spring Boot as an independent cadre can save a lot of things, and Spring Boot does a good job in both large and small tasks.

As a big guy in microservice governance, he thinks very comprehensively, and almost all aspects of service governance are considered, which is convenient for development out of the box.

Spring Cloud is very active, the tutorials are rich, and it is easy to find solutions to problems

With just a few lines of code, various platform functions such as circuit breaker, balance responsibility, and service center are completed.

Compared with Dubbo

Do a simple function comparison:

Core elementsDubboSpring Cloud

Service registry ZookeeperSpring Cloud Netflix Eureka

Service calling method RPCREST API

Service Monitoring Dubbo-monitorSpring Boot Admin

Imperfect Circuit Breaker Spring Cloud Netflix Hystrix

Service Gateway without Spring Cloud Netflix Zuul

Distributed configuration without Spring Cloud Config

Service Tracking without Spring Cloud Sleuth

Message bus without Spring Cloud Bus

Data flow without Spring Cloud Stream

Batch task without Spring Cloud Task

………………

It can be seen from the above figure that the function of Dubbo is only a part of the Spring Cloud system.

This comparison is not fair enough. First of all, Dubbo is a product of the SOA era. Its focus is mainly on service invocation, traffic distribution, traffic monitoring, and circuit breaking. Spring Cloud was born in the era of microservice architecture, considering all aspects of microservice governance. In addition, relying on the advantages of Spirng and Spirng Boot, the two frameworks have inconsistent goals at the beginning. Dubbo positioning service governance and Spirng Cloud are a ecology.

If you only focus on this level of service governance, Dubbo is actually much better than Spring Cloud:

Dubbo supports more protocols, such as: rmi, hessian, http, webservice, thrift, memcached, redis, etc.

Dubbo is more efficient when using the RPC protocol. Under extreme stress tests, Dubbo's efficiency will be more than twice that of Spring Cloud.

Dubbo has more powerful background management. The background management Dubbo Admin provided by Dubbo is powerful, providing routing rules, dynamic configuration, access control, weight adjustment, load balancing and many other powerful functions.

It can limit the access rights of a certain IP traffic, set different servers to distribute different traffic weights, and support multiple algorithms. Using these functions, we can do online grayscale publishing, failover, etc.

Spring Cloud Release Notes

The Spring Cloud project is still in a rapid iteration period, and the version changes quickly. Spring Cloud does not have a familiar digital version number, but corresponds to a development code name.

The official website gives the version information of the corresponding components of each version

Simple explanation:

Regular, but in fact the initials are in order, for example: Dalston version, we can abbreviate as D version, we can abbreviate as E version for the corresponding Edgware version, and the latest Finchley is the so-called F version.

SpringCloud E version corresponds to SpringBoot 1.5.x

SpringCloud F version corresponds to SpringBoot 2.x

Minor version:

SNAPSHOT: Snapshot version, which may be modified at any time.

SRx: Service Release, SR1 means the first official version, generally marked with GA: (Generally Available), which means a stable version.

At the same time, pay attention to a sentence on the official website:

Finchley builds and works with Spring Boot 2.0.x, and is not expected to work with Spring Boot 1.5.x

Xiaobai easy learning tutorial [network disk]

 

Suitable for the crowd:

Java engineer, junior architect, microservice engineer, programming enthusiast


You will learn:

1. Distributed architecture and microservice system
2. Eureka registration center
3. Zuul gateway component
4. Configuration configuration center
5. Communication between Feign services
6. Hystrix service degradation and fuse

Course Introduction:

The real Spring Cloud video for beginners, without complicated concepts, everything uses real cases to explain the mysterious "microservices".

 


 

Guess you like

Origin blog.csdn.net/wshyb0314/article/details/130157029