This article takes you to understand the relevant knowledge of Java microservices, it is worth collecting!

picture

At present, Springcloud microservices are almost an essential skill for Internet companies. For Java programmers looking for jobs, Java microservices are also a very key technical point. Today, I will introduce Springcloud among Java microservices. I hope It can provide some help for everyone to learn about Java microservices!

picture

· Microservices

When it comes to microservices, I believe that many programmers are not unfamiliar. After so many years of development of Internet technology, in order to meet the growing sundance in many technical fields, more and more new technologies have emerged, among which microservices are a very important one. technical points.

From the early monomer architecture, cluster architecture, distributed architecture, to the current mainstream is the microservice architecture, first of all, let's look at the evolution of the Internet technology architecture through a few pictures.

   · Monolithic Architecture Introduction

We all know that when the Internet first started to develop, the number of users was very small, and the number of people with access to the Internet was extremely limited. Therefore, the architect of the Internet at this time is like this, with only one server and one database.

picture

 · Cluster Architecture Introduction

Immediately afterwards, with the development of the Internet and the increase in the number of users (that is, more people who can play with computers), the original single structure cannot support such a large number of user visits. The previous server, now the website is always running Hang up, what’s wrong with this class; the boss gritted his teeth and stomped his feet, one server was not enough, and a few more servers were added, and the technical architecture of the Internet became a cluster architecture just by accident.

picture

 · Introduction to Distributed Architecture

Originally, everything was happening so quietly, as if the universe was in great harmony. Users felt that the Internet speed was soaring, and the bosses also felt that our ideas were so awesome that they could change the world. Unexpectedly, the Internet suddenly ushered in an unprecedented development, because many years ago, an old man drew a circle on the South China Sea.

At this time, all the technologists can’t sit still, what should I do if the website is always stuck, I think that the additional server can’t solve the problem at all, because all the previous businesses are in the same server, which is very complicated. At this time, the business that was previously coupled together began to be split, such as: order module, user module, etc.; in this way, the technical architecture of the Internet will also evolve.

picture

 · Emergence of microservice architecture

Originally, the distributed architecture basically satisfies the current development of the Internet, and everything is happening so quietly, but the big factories are never so peaceful, they are still innovating, and want to further improve efficiency, so they only disassembled from the business unit before. However, it still cannot meet the needs of large manufacturers, so the business has been split into finer grains, and each service can be deployed independently. This is what we call microservices now.

picture

 · Introduction to Spring Cloud

Well, everyone is basically clear about the evolution of the technical architecture of the Internet here. The technology that finally realizes microservices is what we will introduce next. SpringCloud.

Spring Cloud is a master of micro-service architecture. It has integrated a series of excellent components (hodgepodge) and has practical application cases in many large, medium and small companies in China. At present, many companies' business lines all embrace Spring Cloud, and some companies choose to partially embrace Spring Cloud.

Advantages and disadvantages of spring cloud

advantage:

1. The coupling is small and will not affect the development of other modules

2. Reduce the cost of team development, and can achieve parallel development without caring about how other people develop

3. The configuration is relatively simple, basically using annotations, without using too many configuration files

4. Microservices are cross-platform and can use any programming language

5. Each microservice can use an independent database, or share the same database

6. Write the back-end code directly without paying attention to how the front-end is developed, and then expose the interface and communicate between services through components

shortcoming:

1. Deployment is more troublesome, which brings certain troubles to operation and maintenance engineers.

2. Data management is more troublesome, because each microservice can use its own independent database

3. System integration testing is troublesome

4. Performance monitoring is troublesome

Application scenarios of Spring Cloud

1. Applicable to complex business scenarios : Especially for large enterprises, the microservice architecture can split complex businesses into different services, improving the flexibility and maintainability of the system. For example, banking, insurance, telecommunications and other industries have high business repetitions, but need to distinguish multiple services such as users, orders, accounts, and payments. Using the microservice architecture can easily separate different services and improve system scalability. and maintainability.

2. Applicable to business scenarios with large traffic and high concurrency : Generally speaking, large traffic and high concurrency are the technical challenges of the system. Under the traditional single architecture, when the amount of data is large and requests are frequent, it is easy to cause system crashes. Through the microservice architecture, different services can be deployed on different servers, which reduces the pressure on each service and improves the stability and reliability of the system. For example, industries such as e-commerce and online travel have a high number of user visits and need to respond to user requests in real time. The microservice architecture can support high-concurrency business scenarios.

3. Applicable to multi-platform and multi-terminal business scenarios : Modern enterprises usually need to target services to a variety of different terminals, such as web, mobile, and desktop. Using the microservice architecture can adapt different services to different terminals, and at the same time support various cross-platform integrations, such as using Restful API to provide data support. For example, industries such as smart home and e-commerce need to support various multi-terminal applications. Using the micro-service architecture can easily provide services for different terminals.

Summary: The Spring Cloud-based microservice architecture is suitable for complex business scenarios, large traffic, high concurrency business scenarios, and multi-platform, multi-terminal business scenarios. For different enterprises, the specific application scenarios may be different, but adopting the microservice architecture can provide more choices and solutions for the development of enterprise information technology.

Springcloud component introduction

The reason why it is said to be a hodgepodge, we can feel it through the following picture, because it almost covers all the technical components required by the microservice architecture.

picture

There are many components in Spring Cloud, and they are still expanding, so we will introduce a few main components:

  • Eureka : Service governance component, including service registration and discovery

  • Feign : declarative service call component

  • Ribbon : service call component for client load balancing

  • Hystrix : fault-tolerant management component, which implements the fuse

  • Zuul : gateway component, providing intelligent routing, access filtering and other functions

  • Config : Distributed configuration center component, used to unify configuration files

With so many core components, one can easily build a microservice system architecture. Since they are all technologies within an ecosystem, many technologies are compatible, which greatly reduces the door opening for development, so now it is basically the Internet. The company's microservice architecture is adopted, so let's take a look at these components one by one.

 ·  Eureka service governance components

Eureka is a service governance framework developed by Netflix. It is a REST-based service and is mainly used for registration discovery and load balancing between services.

picture

 ·  Feign declarative service call component

Feign is a declarative web service client, a load-balanced HTTP client. Using Feign to call an API is like calling a local method, which avoids the tediousness of constantly parsing/encapsulating json data when calling the target microservice , usually implemented together with the Ribbon.

picture

 ·  Ribbon load balancing component

Ribbon is a client-side load balancing tool based on HTTP and TCP, and the declarative service call provided by Feign is also implemented based on this Ribbon. Ribbon provides many load balancing algorithms by default, such as round robin, random and so on. We can also customize the load balancing strategy according to our own needs.

picture

 ·  Hystrix fuse current limiting component

The Hystrix component is a bit complicated because it may not implement a specific function. Its main role is to improve the high availability and stability of the system. In a distributed system environment, various dependencies between services, a business call usually depends on Multiple underlying services are very common. Hystrix plays the role of monitoring services and service fault tolerance. If the problem is not dealt with in time, an avalanche is likely to occur, and the consequences will be disastrous.

picture

 ·  Zuul service gateway component

Zuul is a microservice API gateway and the first gateway for user access. All user requests will pass through Zuul to reach the back-end application. Zuul provides dynamic routing, monitoring, elastic load, and security features. The bottom layer of Zuul uses various filters to achieve the following functions:

  • Authentication and security , identifying each resource that requires authentication and rejecting requests that do not meet the requirements.

  • Performance monitoring , tracking and statistics at the service boundary, providing an accurate view of production.

  • Dynamic routing , dynamically routing requests to backend clusters as needed.

  • Stress testing , gradually increasing the traffic to the cluster to understand its performance.

  • Load shedding , which pre-allocates capacity for each type of request and automatically drops requests when they exceed capacity.

  • Static resource handling , returning certain responses directly at the boundary.

Therefore, at the gateway level, in addition to the core routing function, it is also a means of current limiting.

picture

 ·  Config distributed configuration center component

Config is a configuration management solution for distributed systems. It includes two parts, Client and Server. The server provides the storage of the configuration file and provides the content of the configuration file in the form of an interface. The client obtains data through the interface and initializes its own application based on this data. It is also often used together with Ctrip's open source Apollo at work.

picture

Well, here is the basic introduction to several core components of SpringCloud. If we get these core components, we will basically get the core knowledge of microservices!

Guess you like

Origin blog.csdn.net/xishining/article/details/131778912