Springboot must know series (1) - springboot and microservices

my capriciousness

At the beginning of the year, I wrote a few blogs about springboot, but I thought it was a little less organized. I wanted to continue writing, but when I wrote spring cloud, I found that many things had not been sorted out before, so I decided to give up and start anew.

This time I plan to plan the entire series and divide it into two parts:

The first half introduces all the usage methods and basic principles that must be known: including (1) springboot and microservice-related content, (2) how to configure, (3) integration with common log frameworks log4j, slf4j, logback, etc., (4) ) Various problems of springboot in web development, (5) the integrated application of springboot and virtualized container technology docker, (7) functions of springboot and data access (springboot bottom layer uses spring data to access sql and nosql data) , (8) The internal principle of springboot.

The second half introduces some advanced application scenario integration and features, such as caching, messaging, retrieval, etc.: including (1) springboot's cache management mechanism, we will use redis as a cache server as an example to introduce; (2) springboot and message middleware , such as rabbitmq integration; (3) springboot and full-text retrieval ES integration; (4) springboot and mail tasks, timed tasks, asynchronous tasks (improving concurrency capabilities); (5) springboot's security mechanism (the security framework used at the bottom of springboot is spring security); (6) the integrated use of springboot and distributed, zookeeper and Dubbo, and the integrated use of springcloud; (7) and the main points about deploying and operating springboot applications (springboot development hot deployment and monitoring management).

It can be seen that springboot is not a simple framework, but a complete one-stop solution for J2EE.

(This article is from the blog post of oschina blogger happybks: https://my.oschina.net/happyBKs/blog/1805314)

Why does springboot appear?

The development of all technical frameworks seems to follow a main line: a specification framework is derived from a complex application scenario, and people only need to perform various configurations without implementing it themselves. At this time, the powerful configuration function becomes an advantage; After the development reaches a certain level, people select the practical functions and design essences according to the actual production and application conditions, and reconstruct some lightweight frameworks; later, in order to improve the development efficiency, the original various configurations are too troublesome, so they begin to advocate "" Convention is greater than configuration", which in turn derives some one-stop solutions.

Yes, this is the process of Java enterprise application->J2EE->spring->springboot.

 

goal of springboot

Spring Boot simplifies the development of Spring applications. The convention is greater than the configuration, and the complexity is simplified. As long as you run it, you can create an independent one.

The simplified method is: include starter starters to manage various dependencies and configurations, you only need POM to introduce these starts, and all configurations basically springboot start will be configured by itself, no need for your heart.
 

spring family bucket

Nowadays, there are more and more spring projects, but the most popular ones are Spring Boot and Spring Cloud:
Spring Boot: J2EE one-stop solution
Spring Cloud: Distributed overall solution

 

Advantages of springboot:

(1) Quickly create independent running Spring projects and integrate with mainstream frameworks

(2) Using the embedded Servlet container, the application does not need to be packaged as a WAR package

    Springboot's web project no longer requires us to configure a tomcat class to import related servlets. It contains its own servlet container, and you can make a jar to run a web project.

(3) Automatic dependency and version control of starters

All enterprise-level development scenarios have corresponding launchers, which help us import all the dependencies required for this scenario and automatically control the version.

For example, if you want to use Mongo, ES, redis, develop web projects, etc., you only need to introduce the corresponding starter under the pom of maven. Note that taking mongo as an example, it does not introduce a driver like a general project, but a springboot mongodb starter. It will not only import the various jars related to the java access mongo driver according to the correct version, but also make various configurations for us by default. We directly inherit some abstract classes or interfaces and use them directly.

(4) A large number of automatic configurations, simplify development, and modify default values

To develop applications with springboot, users only need to develop a tiny entry; we don't need to do a lot of configuration, most of the configuration springboot has been automatically configured for us.

(5) No need to configure XML, no code generation, out of the box

Springboot does not need to configure xml, not because it will automatically generate the corresponding code, but springboot has implemented some APIs, which can help us configure it automatically. We can use it as long as we create it through springboot.

(6) Runtime application monitoring for quasi-production environments

The health status during operation and maintenance, the status of each service, etc. can be monitored.

(7) Natural integration with cloud computing

 

So what are the disadvantages of springboot?

In fact, if I have to say a shortcoming, I can only say that the convenient springboot has made some programmers lose the opportunity to have a deeper understanding of its encapsulation and implementation principles. Because springboot is repackaged on the basis of spring. When you learn the internal implementation principle of springboot, you will find that you must understand a large number of APIs inside spring. So if you need deep customization of springboot, you must have a good understanding of spring itself.

 

Summarize

The purpose of springboot is to build a framework that simplifies spring development

The springboot framework itself is a big integration of the spring technology stack

springboot is a one-stop solution based on J2EE

 

 

Microservices

What are microservices?

Microservice is an architectural style that requires us to build an application as a combination of a series of small services when developing an application;

It is possible to communicate via http.

To talk about the microservice architecture, we must first talk about our single application architecture in the past.

Monolithic application architecture (All in one)

The so-called monolithic application architecture means that we encapsulate all application services in an application in one application.

Whether it is ERP, CRM or any other system, you put database access, web access, and other functions into a war package.

The advantage of this is that it is easy to develop and test; it is also very convenient to deploy; when you need to expand, you only need to copy multiple copies of the war, and then put them on multiple servers, and then do a load balancing.

The disadvantage of the monolithic application architecture is that even if I want to modify a very small place, I need to stop the entire service, repackage and deploy the application war package. Especially for a large-scale application, it is impossible for us to put all the content in one application. How we maintain and how to divide and cooperate is a problem.

 

 

 

Microservice Architecture

With the all in one architecture, we put all functional units in one application. Then we deploy the entire application to the server. If the load capacity is not enough, we will replicate the entire application horizontally, scale, and then load balance.

The so-called microservice architecture is to break the previous all-in-one architecture and separate each functional element. The dynamic combination of independent functional elements is used to combine the required functional elements. When more functional elements are needed, multiple functional elements can be integrated. So a microservice architecture replicates functional elements, not the entire application.

The benefits of doing this are:

(1) Save calling resources.

(2) The service of each functional element is a replaceable, independently upgradeable software code.

 

Microservices vs SOA

How small should microservices be? You can check out Martine Flower's article on comparing microservices and SOA:

https://martinfowler.com/articles/microservices.html#MicroservicesAndSoa

I won't go into details here, I'll talk about it when I re-write the spring cloud article later.

 

How to Build Microservices

The microservice architecture of a large-scale system is like a complex and intertwined neural network. Each neuron is a functional element. They each perform their own functions and then request and call each other through http. For example, in an e-commerce system, services such as checking caches, connecting to databases, browsing pages, checking out, and paying are all independent functional services, and they have all been miniaturized. As microservices, they build a huge system together. If you modify one of the functions, you only need to update and upgrade one of the function service units.

However, this huge system architecture brings great difficulty to deployment and operation and maintenance.

Therefore, spring brings us a complete set of products for building large-scale distributed microservices:

To build a functionally independent microservice application unit, you can use springboot to help us quickly build an application;

Invocation of large-scale distributed network services, this part is completed by spring cloud to achieve distributed;

In the distributed middle, for streaming data computing and batch processing, we have spring cloud data flow.

Spring has figured out the whole process plan for us from the beginning of building applications to large-scale distributed applications.

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325117889&siteId=291194637