Daniel's 20 years of actual combat summary SpringCloud microservice distributed system documentation has finally been exposed!

Preface

This article is a unique perspective of the combination of microservices and distributed development, showing a summary of actual combat experience from front-line developers. I hope everyone can read it carefully, grasp the essence of it, and continuously improve the depth and breadth of their technology, so that they can be better in the enterprise. Survive well!

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

This article will share with you all the technical knowledge of SpringCloud microservices and distributed system practice. There are a total of 527 pages and 20 chapters. Because the content is too much, I can’t show you all in this article, so I can only show some The knowledge points are taken out for everyone to introduce, and each chapter has more detailed content!

table of Contents

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Main content

Chapter 1 Overview of Distributed and Microservices;

  • 1.1 Characteristics of the Internet system
  • 1.2 Overview of distributed systems
  • 1.3 Design principles of distributed systems
  • 1.4 Microservice architecture
  • 1.5 Spring Cloud
  • 1.6 Introduction to sample microservice system

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 2 Technical Basics; In order to better introduce Spring Cloud, here is a little introduction to the REST style of Spring Boot and HTTP. Because Spring Cloud is based on Spring Boot, and each service system is integrated through REST-style requests, learning them will help us to learn Spring Cloud in depth. Of course, if you are already familiar with them, you can skip this chapter and go directly to Chapter 3.

  • 2.1 Spring Boot
  • 2.2 Introduction to REST style

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 3 Service Governance-Eureka; Eureka is the service governance center of Spring Cloud. After using Spring Boot for secondary packaging, the use of Eureka is very simple. As a governance center for microservices, Eureka is a service application that can receive registrations of other services, as well as discover and manage service instances.

  • 3.1 Service Management Center
  • 3.2 Eureka governance mechanism
  • 3.3 Eureka placement

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 4 Client Load Balancing-Ribbon; Spring Cloud Netflix Ribbon is a component of client load balancing. For convenience, it is referred to as Ribbon in this article. In the microservice architecture, we divide the system according to the business, but an actual business often requires multiple microservices to cooperate with each other to complete, so there are service calls between various microservices.

In Spring Cloud, the service calls provided are Ribbon and OpenFeign. Ribbon is a component developed by Netflix, and Spring Cloud makes it easier to use through secondary packaging. OpenFeign is actually implemented based on Ribbon.

Calls between microservices are often referred to as "client load balancing", because in Eureka's mechanism, any microservice is Eureka's "client". Through the study of Chapter 3, we can know that there can be multiple instances of a microservice. When making a service call, you need to select a specific instance to call, which needs to be implemented through a specific load balancing algorithm. Just like our example in Chapter 3, the product microservice may call the funding microservice, but the funding microservice is divided into multiple instances. How to obtain multiple instances under the funding microservice is the function of obtaining and maintaining the service instance list. How to select a specific service instance is the function of load balancing.

  • 4.1 Overview of Load Balancing
  • 4.2 First acquaintance with Ribbon
  • 4.3Ribbon load balancer and strategy
  • 4.4 Maintenance of Ribbon Service Instance List
  • 4.5 Customize the Ribbon client
  • 4.6 Ribbon usage practice

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 5 Circuit Breaker-Hystrix; Spring Cloud Netflix Hystrix is ​​a circuit breaker component. In this book, if there is no special instructions, it will be referred to as Hystrix for short. In fact, before writing this chapter, I have been hesitant to write Hystrix, because Netflix's open source current limiting component Hystrix has announced on its GitHub homepage that it will no longer develop new features, and only maintain it based on existing features. Therefore, the Spring Cloud community recommends developers to use other open source projects that are still active. The most recommended one is Resilience4J, and the Spring Cloud community is also stepping up the development of spring-cloud-circuitbreaker to replace Hystrix. But this project is still under development and has not been released. In addition, many companies are currently using Hystrix, and the technology is interlinked, so I decided to introduce Hystrix.

  • 5.1 Overview
  • 5.2 Getting Started Examples
  • 5.3 Hystrix working principle
  • 5.4 Hystrix practice
  • 5.5 Dashboard
  • 5.6 Hystrix property configuration

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 6 New Circuit Breaker——Resilience4j; Resilience4j is a lightweight and easy-to-use fault-tolerant framework. It is inspired by Netflix's Hystrix and is designed based on Java8 and functional programming, so when using it, You can see a lot of functional programming designs.

  • 6.1 Circuit Breaker (CircuitBreaker)
  • 6.2 Rate Limiter (RateLimiter)
  • 6.3 Bulkhead
  • 6.4 Retry
  • 6.5 Cache
  • 6.6 Time Limiter (TimeLimiter)
  • 6.7 Mixed use of components
  • 6.8 Configuration method using Spring Boot 2

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 7 Declarative Call-OpenFeign; this article from Chapter 3 to Chapter 6, introduces the core content of microservices : service governance, service invocation (Ribbon) and fuse (Hystrix and Resilience4j). These are all powerful tools for microservices, but from a developer's point of view, the ones we deal with most are service calls and fuses. Service invocation enables multiple microservices to serve the same business by invoking each other. The fuse can guarantee the service call to a large extent. However, strictly speaking, it is more troublesome to write Ribbon using the REST request method, and it is not very friendly to developers. Therefore, on the basis of the REST request method, some developers also provide the call of the interface declaration method. For example, we will The introduced GitHub OpenFeign is like this.

  • 7.1 Use of OpenFeign
  • 7.2 Placement Hystrix
  • 7.3 Use Resilience4j to call OpenFeign interface

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 8 Old API Gateway - Zuul; In the previous chapters, we learned about service registration and discovery (Eureka), through which we can manage our services smoothly; learned about the calls between services (Ribbon and OpenFeign) , Let the various services be connected, and complete the business logic through joint assistance; also learned the circuit breaker (Hystrix and Resilience4j), which can protect the calls between microservices as much as possible, and avoid the rabbit service dependence caused by the fuse method. Avalanche. The above mentioned are the core components of Spring Cloud microservices.

In this chapter, let us learn the last core component of microservices ~ API gateway. Netflix Zuul is an API gateway, and its main function is to provide gateway services.

  • 8.1 What is a gateway
  • 8.2 Examples of getting started with Zuul
  • 8.3 Zuul Principle-Filter
  • 8.4 Current limit
  • 8.5 Dynamic routing
  • 8.6 Grayscale release (canary release)
  • 8.7 Using Hystrix Tolerance

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 9 New Gateway-Spring CloudGateway; In Chapter 8, we talked about the old gateway Netflix Zuul, and told readers that Zuul 1.x is just a gateway with average performance, and the Netflix Zul 2.x version is often not released as scheduled , So the new version of Spring Cloud does not plan to bundle Zuul. The new version of Spring Cloud provides a new gateway for developers to use, this is Spring Cloud Gateway. For the sake of simplicity, unless otherwise specified, it will be referred to as Gateway for short. Gateway does not use the traditional JakartaEE Servlet container, it is developed using reactive programming. In Gateway, a Netty-based operating environment provided by Spring Boot and Spring WebFlux is required.

  • 9.1 Get to know Gateway
  • 9.2 Predicate
  • 9.3 Overview of Filter
  • 9.4 Built-in filter factory
  • 9.5 Custom filters
  • 9.6 Gateway knowledge supplement

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 10 Configuration --- Spring Cloud Config; Spring Cloud Config (for convenience, when there is no ambiguity, the whole book is abbreviated as Config) is a project that supports microservices and distributed centralized configuration. There may be many instances in the microservice architecture. If you update the configuration one by one, the operation and maintenance costs will be very large. In order to simplify the complexity of configuration, some developers put forward the concept of centralized management configuration, that is, to provide a centralized configuration center so that we can uniformly configure each microservice instance. The Config to be discussed in this chapter is designed for this purpose.

  • 10.1 Getting Started Example—Using Git Repository
  • 10.2 Use other methods to achieve configuration
  • 10.3 Detailed explanation of the use of the server

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 11 Spring Cloud Sleuth full link tracking; in the previous chapters, we learned about the Eureka Service Management Center, through which we can manage various services so that they can work collaboratively with each other. However, as the business becomes more complex, the service becomes more complicated, and each service can have multiple instances. Once a problem occurs, it will be difficult to find the root cause of the problem. In order to solve this problem, many distributed developers have developed their own link monitoring components to enable requests to be traced to various service instances, such as Google's Dapper, Twitter's Zipkin and Alibaba. (Alibaba)'s EagleEye, they are all currently well-known link tracking components.

  • 11.1 Basic concepts of link tracking
  • 11.2 Spring Cloud Sleuth和Zipkin
  • 11.3 Examples
  • 11.4 Endurance

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 12 Monitoring of Microservices-Spring Boot Admin; In an excellent distributed system, it is very important to monitor service instances and discover problems in the instances in time. Spring Boot Admin provides such a function. For convenience and without causing ambiguity, Spring Boot Admin will be referred to as Admin for short below. Admin is a monitoring platform that can detect each Spring Boot application, allowing operation and maintenance personnel and developers to discover problems in each service instance in time. Admin is a console based on Spring Boot Actuator, that is, it can monitor the running status of each instance through the endpoints exposed by Spring Boot Actuator. Admin's user interface (USser Interface, UI) is built using AngularJs applications.

  • 12.1 Introduction to the examples in this chapter
  • 12.2 URL registration method
  • 12.3 Service discovery registration method
  • 12.4 Use Spring Security to protect the Admin server

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 13 Generating a Unique ID-Number Issuing Mechanism; In the database (please note that in this chapter, unless otherwise specified, the databases mentioned are all relational databases, not including non-relational databases like Redis In ), the primary key is often the unique identifier of a record, and it is unique. In a single machine, only the problem of a single database needs to be considered, which is relatively simple, but in a distributed and microservice system, it is relatively difficult, because it involves collaboration between multiple machines. So how to ensure that a unique ID is generated under multiple nodes of distributed or microservices, and how to make the ID have a certain readability? This requires a number issuing mechanism to control. How to implement the number issuing mechanism is the issue to be discussed in this chapter.

  • 13.1 Common ways to generate ID
  • 13.2 Customized number issuing mechanism

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 14 Distributed Database Technology; In Chapter 1, we talked about the increase in Internet membership and the complexity of business, which will inevitably lead to the storage of big data. At this time, the use of a stand-alone database for data storage and access becomes difficult. The division method is also discussed in Chapter 1, mainly horizontal, vertical and mixed division methods. For distributed and business services, a business may have a lot of data, such as transactions. A single database may not be able to support it. Multiple database nodes are required to support it. This requires splitting the database into multiple nodes. The storage technology is the distributed database technology that needs to be discussed in this chapter. In order to better explain the knowledge of distributed databases, we first start with database knowledge such as sub-tables, sub-databases, and partitions. However, in this chapter we will not discuss the related knowledge of distributed transactions, which will be discussed in the next chapter.

  • 14.1 Basic knowledge
  • 14.2 Development environment setup
  • 14.3 Fragmentation Algorithm
  • 14.4 ShardingSphere

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 15 Distributed Database Transactions; In the previous chapter, we discussed the knowledge of distributed databases, mainly sharding technology. In this chapter, we will discuss distributed database transactions. We know that in the Internet world, some data has very strict requirements for consistency, such as commodity inventory and user account funds, but these are most likely to be stored separately In different database nodes, how to ensure the consistency of these data in multiple database nodes is a problem to be solved by distributed database transactions.

Distributed database transactions are much more complicated than stand-alone database transactions, and it involves collaboration between multiple database nodes. In Chapter 1, I talked about the BASE theory. In distributed databases, there are strong and weak consistency. The so-called strong consistency means that any access by multiple subsequent threads or other nodes will return the latest value. Weak consistency means that when the user completes the update operation on the data, it does not guarantee that the latest value will be accessed immediately in the subsequent threads or other nodes. It only uses some method to ensure the final consistency. The advantage of strong consistency is that it is more friendly to developers, and the data can always be read to the latest value, but this method requires a complicated protocol and a lot of performance needs to be sacrificed. Weak consistency is relatively unfriendly to developers, and there is no guarantee that the read value is the latest, but there is no need to introduce complex protocols, and there is no need to sacrifice a lot of performance. In fact, in the event of a certain inconsistency, we can take a variety of ways to remedy it. The fast user experience is often more important than ensuring strong consistency. Therefore, in today's Internet development, weak consistency occupies a dominant position. From the perspective of microservices, strong consistency does not conform to the design philosophy of microservices, which will be explained in this chapter.

  • 15.1 Strong-Conscientious Affairs
  • 15.2 Weak-Consistent Affairs
  • 15.3 Practical theory of distributed transaction application

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 16 Distributed Cache-Redis;

  • 16.1 High Availability of Redis
  • 16.2 Use-Consistent Hash (ShardedJedis)
  • 16.3 Distributed Cache Practice

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 17 Distributed Session; Session (session) refers to a piece of memory space allocated by the server during the interaction between the client and the server. It is used to store the data interacting between the client and the server, for example, a typical Shopping cart for e-commerce website. This piece of memory space is shared by the corresponding client and server, and it can store the data that needs to be temporarily stored and commonly used, so that it can be read out quickly and easily. In the session mechanism, in order to enable the browser and the server to correspond, a character string is used for association, for example, the sessionId in Tomcat. In a single system, because there is only one server instance, you only need to store the user's data in your own memory and you can read it out repeatedly. In a distributed system, there are multiple server nodes, and these nodes are even cross-service. If the session information is only on one node, a certain mechanism is needed to ensure that the session can be shared among multiple service nodes. This is Distributed sessions to be discussed in this chapter. In a distributed session, the most important function is security verification, because different users have different permissions.

  • 17.1 Several ways of distributed sessions
  • 17.2 Sticky conversation
  • 17.3 Server session replication
  • 17.4 Use cache (spring-session-data-redis)
  • 17.5 Persist to the database

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 18 Distributed System Authority Verification; In computer systems, authority is often an important part. In a single system, permissions are often easy to control, but in a distributed system, it is not. Because there is often only one node in a single system, it is enough to solve a single point. However, the distributed system is a multi-node collaboration. After one node passes the verification, the other node does not pass the verification, so this chapter will talk about the authorization verification of the distributed system. In fact, the use of cache storage session (spring-session-data-redis) mentioned in the distributed session can also support distributed permission verification to a certain extent, but everything needs to start with the most basic Spring Security Up. Because there are many things involved here, I still created a new project and named it chapter18 so that I can add corresponding modules as needed.

  • 18.1 Spring Security
  • 18.2 Custom Microservice Permission Control
  • 18.3 Overview of OAuth 2.0
  • 18.4 Spring Cloud Security

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 19: Remote Procedure Call; Remote Procedure Call (RPC) is a method of service invocation, and it has also been used in many enterprises. In fact, in microservices, it is recommended that we use REST-style calls instead of RPC. So why do you need to use RPC and how do you use it?

  • 19.1 Remote procedure call
  • 19.2 Introduction to Thrift
  • 19.3 Summary of RPC

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

Chapter 20 Microservice Design and High Concurrency Practice; The above chapters have explained most of the content of building microservices, this chapter mainly talks about microservice practices. In microservices, the big problem to be solved is high concurrency, which is also one of the most concerned issues in distributed.

  • 20.1 Principles of Microservice Design
  • 20.2 Some optimization experiences of high-concurrency systems
  • 20.3 Examples of Simple Microservice System

Daniu 20 years of actual combat summary SpringCloud microservice distributed system documentation

 

This [SpringCloud Microservices and Distributed System Practice] has a total of 527 pages. Friends who need the full version can get it with one click, three links + comments, scan the code below!

Summary of this article

  • This article explains the principles and applications of the basic components of the Spring Cloud microservice system combined with practice;
  • This article explains the relevant knowledge of distributed systems in combination with microservices;
  • This article explains the development of microservice (distributed) system in combination with the real needs of enterprises;

Who are the target readers of this article?

Reading this article requires readers to have prior knowledge of Java EE basics, Spring Boot, database and Redis.

Reading this article, readers can learn not only the method of building an enterprise-level microservice system through Spring Cloud, but also some commonly used distributed knowledge. Therefore, this article is suitable for all kinds of Java developers who want to learn Spring Cloud microservices and distributed system development, including beginners and development engineers. This article is also helpful to architects.

I hope that this article can help you learn, so that you can continuously improve your technical breadth and depth, and make yourself more valuable. I also hope that this article can be liked by everyone! Repost this article and follow the editor, so that more friends will benefit!

Guess you like

Origin blog.csdn.net/bjmashibing001/article/details/110231533