SpringCloud learning notes 01

Posted by Simon Mayer on Thu, 10 Feb 2022 21:13:50 +0100

1, Introduction, chat and course description

1. Course content (SpringCloud + SpringCloud alibaba)

2. Technical requirements

     java8+maven+git,github+Nginx+RabbitMQ+SpringBoot2.0

3. Listen to the audience and climb the stairs at the beginning

Students: Zero foundation + non subject class + liberal arts sister JVM/JUC/GC/Nginx...

Stage 0 (Chapter 1-4) - initial (Chapter 5-9) - medium (Chapter 10-16) - high (Chapter 17-21)

4. Continuous learning

2, Introduction to micro service theory

It's important in theory

01. Concept of micro service architecture

Microservice architecture is an architecture model, which advocates dividing a single application into a group of small services. Services call and cooperate with each other to provide final value for users. Each service runs in its own independent process, and lightweight communication mechanism is adopted between services to cooperate with each other (usually RESTful API based on HTTP protocol). Each service is built around specific business and can be independently deployed to production environment, class production environment, etc. In addition, a unified and centralized service management mechanism should be avoided as far as possible. For a specific service, appropriate languages and tools should be selected according to the business context

==============================

For example: I now place an order to call inventory, adjust inventory, pay, pay, warehouse and logistics, logistics, successful delivery, increase points for others, etc

One module by one is a micro service developed by SpringBoot. Previously, there was only one set of only one. Multiple services need a mechanism to manage them

Springboot is a micro service that provides functions one by one (order module, inventory module, warehousing module, integral module and payment module). The services need to coordinate and cooperate with each other, and finally run in an independent process,

There are two ways:

1. Huawei mobile phones, ThinkPads, Lenovo laptops, smart appliances, tmall genie, tablet computers, apple, life bags and other brands are somewhat similar to assembly machines

2. We have only one service brand. Mobile phones, computers and so on are all Apple brands, which is a bit similar. Suppose your theme needs a variety of landing dimensions and technical support, either brand or hybrid

We don't want to run around now. A manufacturer provides a package solution to package our dimensions in one piece, such as Xiaomi

If provided by a manufacturer, the compatibility is very good

Distributed microservice architecture

In the middle of the official website of SpringCloud is microservices. The icon is SpringBoot. The things developed by SpringBoot are specific landing functions

Integrating, coordinating and assembling everything: making it easier to build distributed systems

API Gateway: Gateway

breaker dashboard: monitoring dashboard

service registry: service registry

message brokers: Message Middleware

databases: Database

distributed tracing: distributed link tracing

config # dashboard: configuration center

Talk about your understanding of distributed microservice architecture?

You say you live a digital life. You can't say there is only a mobile phone, only a computer. There must be a pile of things

You say you are a distributed microservice architecture, and you can't use only one technology. It must be the competition and confrontation between a whole set of systems of the distributed microservice architecture. Therefore, so many landing technologies and dimensions constitute the system of the distributed microservice architecture. Its strength is not an individual, but a whole. The technical manager considers the whole Overall, what programmers want is a specific function of landing

Spring cloud is an embodiment of distributed microservice architecture technology, which should have multiple dimensions

SpringCloud = a one-stop solution of distributed microservice architecture, which is a collection of landing technologies of a variety of microservice architectures, commonly known as microservice architecture

Spring cloud seems to have become the mainstream technology stack of microservice development

Large factory micro service architecture

1. Jingdong

2. Ali

3. Jingdong Finance

Non business basic services and business based basic services

03. SpringCloud technology stack

Current microservice architecture (general)

After coming here, the inside of the frame is the inside of the system of SpringBoot and SpringCloud, and the outside is the third-party

First of all, through a micro service gateway (NETFLIX), spring cloud actually copied NETFLIX

Generally, it is through a service gateway to find the registration, and then go to the configuration center to read. n multiple microservices developed by SpringBoot are used for coordination and scheduling. Authentication, fault tolerance and current limitation, degradation, fusing, etc. are required

Finally, the whole service runs. We need monitoring, logs, health checks and alarms

The idea of flying in the sky must be realized by landing

Spring cloud calls these load balancers through the gateway, and schedules each micro service A, B and C

3, Selection of Boot and Cloud versions in the second quarter

SpringBoot is a technology, and SpringCloud is a package solution of distributed micro service architecture, with the implementation of a variety of technologies

SpringBoot2. Version x and springcloud version H

 

View on SpringCloud official website

More detailed version corresponding viewing methods: https://start.spring.io/actuator/info

json online tools: https://tool.lu/

Final version requirements

4, Description of Cloud component shutdown

Stop / upgrade / replace various Cloud components

"Escalation tragedy" caused by stopping Watch:

Stop changing without stopping: 1. Passively fix bugs; 2. No longer accept merge requests:

 

Spring cloud is a family bucket and a master of distributed micro service technology. Now we mainly study the mainstream technologies used in enterprises

The concept will be realized

dubbo calls the service and zookeeper registers the service

1,

2,

5, Parent Project space new

Order payment module micro service

Convention > configuration > encoding

6, Parent project pom file

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.nanjing.springcloud</groupId>
    <artifactId>cloud2021</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging><!--Total parent project->

    <!--unified management  jar Package version-->
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <junit.version>4.12</junit.version>
        <log4j.version>1.2.17</log4j.version>
        <lombok.version>1.16.18</lombok.version>
        <mysql.version>5.1.47</mysql.version>
        <druid.version>1.1.16</druid.version>
        <mybatis.spring.boot.version>1.3.0</mybatis.spring.boot.version>
    </properties>

    <!--After the sub module inherits, it provides the following functions: locking the version+son modlue Do not write groupId and version -->
    <dependencyManagement>
        <dependencies>
            <!--spring boot 2.2.2-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.2.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud Hoxton.SR1-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--spring cloud alibaba 2.1.0.RELEASE-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.1.0.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>${mysql.version}</version>
            </dependency>
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>${druid.version}</version>
            </dependency>
            <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>${mybatis.spring.boot.version}</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
            </dependency>
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>${lombok.version}</version>
                <optional>true</optional>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <fork>true</fork>
                    <addResources>true</addResources>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

7, Review DependencyManagement and Dependencies

Temporarily blank

8, Construction of payment module (Part I)

The order module can call the payment module

Microservice module

1. Create module

2. Change POM

3. Write YML

4. Main start

5. Business class

9, Payment module construction (in progress)

vue-controller-service-dao-mysql

10, Construction of payment module (Part 2)

11, Hot deploy Devtools

ctrl+shift+Alt+/  

12, Consumer order module (Part 1)

RestTemplate provides a variety of convenient ways to access remote http services

It is a simple and convenient module class for accessing restful services. It is the client template tool set provided by Spring for accessing restful services

RestTemplate is to complete the remote call of ports 80 to 8001. It is an encapsulation of call interface mode, which is similar to httpClient

You need to inject {RestTemplate into the container of SpringBoot

13, Consumer order module (next)

1. Note @ RequestBody when making a post request

2. Open Run DashBoard

14, Engineering reconstruction

Extract entities entity classes to public api modules

15, Eureka Basics

The update has stopped

1,

2. Service governance

3. Service registration and discovery

Eureka two components

16, EurekaServer server installation

Because there is no registered service, of course, no service can be found

17, Payment micro service 8001 settled in eurekaServer

18, Order micro service 80 settled in eurekaServer

19, Eureka cluster principle description

High availability, stacking must be the cluster effect, and the stand-alone version is over.

Solution: build Eureka registry cluster to realize load balancing + fault tolerance

External exposure is a whole. There are multiple Eureka, which register and watch each other. 7001 points to 7002, the opposite is the same. In a word, I must have all the relevant information of all my brothers in this circle

20, Construction of Eureka cluster environment

21, Two micro services for order payment are registered into Eureka cluster

22, Payment micro service cluster configuration

23, Actor micro service information improvement

health examination

24, Service Discovery

For the microservices registered in eureka, the service information (host name, port number) can be obtained through service discovery

step

25, Eureka's theoretical knowledge of self-protection

1,

2,

3,

4,

26, How to prohibit self-protection

Test in stand-alone version

27, Eureka stop instruction

English version

https://github.com/Netflix/eureka/wiki

28, Registration of payment service into zookeeper

29, Temporary or persistent node

Is the service node a temporary node or a persistent node? Temporary node

30, Order service registered in zookeeper

Topics: Distribution Spring Cloud