Spring Cloud microservice Architecture - getting started creating parent project

I Spring Cloud microservice architecture

1. What is micro service

The foundation of microservice architecture (MSA) is to split a single application into multiple independent small services, which can be developed, deployed and run independently.

2. Core component analysis

Spring Cloud Alibaba provides the following core functions by default (first understand):

Service current limiting degradation:
By default, it supports the access of WebServlet, OpenFeign, RestTemplate, spring cloud gateway and rocketmq current limit and degradation function. It can modify the current limit and degradation rules in real time through the console during operation, and it also supports the view of current limit and degradation Metrics monitoring.
Service registration and discovery:
Based on the Spring Cloud service registration and discovery standard, it is implemented with the help of Nacos. By default, it also integrates the support of Ribbon.
Distributed configuration management:
Nacos supports externalized configuration in distributed system, which will be refreshed automatically when the configuration changes.
Message driven capability:
Build message driven capabilities for microservice applications based on Spring Cloud Stream.
Distributed transactions:
Use @ GlobalTransactional annotation to solve the problem of distributed transactions efficiently and without business intrusion..
Distributed task scheduling:
Provide second level, accurate, highly reliable and highly available timed (based on Cron expression) task scheduling service. At the same time, it provides a distributed task execution model, such as grid tasks. Grid tasks support the uniform distribution of tasks among all workers.

II Engineering structure of spring cloud aggregation project

III Create project and corresponding configuration (idea)

Open Idea and create an empty project named cgbmsc

This empty project (empty folder) will be used as the code workspace

1. Project initialization configuration

Step 1: configure maven environment (reconfigure as long as it is a new workspace). Pay attention to the new location of the local library. Do not share the local library with other projects, because multiple projects need to rely on different versions, and there may be some conflicts between dependent versions.

Note that there should be no spaces between Chinese words in the local library
Step 2: configure JDK compilation environment
During the compilation of aggregation project, the related dependent projects need to be compiled together, so some configurations need to be made as follows

Specify the jdk compiled version of the current workspace as follows

Step 3: configure the item coding method in the workspace

2. Create aggregate parent project

Step 1: create parent project module


Step 2: delete the src file in the project (the parent project does not need this file)

Step 3: modify the POM of the parent project XML file

<!--Unified dependent version(All subprojects will refer to the version definitions here),
        dependencyManagement Element is only responsible for defining dependent versions-->
    <dependencyManagement>
        <dependencies>
            <!--definition Spring Boot Dependent version-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.3.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--definition Spring Cloud Dependent version-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR9</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <!--definition Spring Cloud Alibaba Dependent version-->
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>2.2.6.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <!--Define public dependencies(Dependencies required by all subprojects,Subsequent sub projects need not be added)-->
    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <!--exclude junit4 This group of dependencies-->
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
    <!--Define a unified compilation and running environment-->

Create a service provider module and inherit the parent project

Create service consumer

Create API gateway service module

Design diagram of service relationship and invocation relationship

Keywords: Java Spring Cloud Microservices

Added by navarre on Thu, 24 Feb 2022 14:30:58 +0200