Microservice summary

The foundation of microservice architecture (MSA) is to develop a single application into a group of small independent services, which run in their own process, develop and deploy independently.

The microservice in the program is to extract the commonness of each business system and make it into an independent service.

  SpringCloud Alibaba microservice solution

Overview Spring Cloud Alibaba is a sub project of Spring Cloud, which is committed to providing a one-stop solution for microservice development. This project contains the necessary components for developing distributed application microservices, so that developers can easily use these components to develop distributed application services through the Spring Cloud programming model. Relying on Spring Cloud Alibaba, you only need to add some annotations and a few configurations to connect Spring Cloud applications to Alibaba microservice solutions and quickly build distributed application systems through Alibaba middleware

Core component analysis
Spring Cloud Alibaba provides the following core functions by default (learn about them first):

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 at runtime, and it also supports the viewing 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, and Ribbon support is integrated by default.
Distributed configuration management:
Nacos supports externalized configuration in distributed systems, and automatically refreshes 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 distributed transaction problems 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 to all workers for execution.
 

Create a new microservice project

Open Idea and create an empty project named GitCGB2108IVProjects

 

  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

It is better not to choose Chinese for the local library name, and there should be no spaces between words.

 

Step 2: configure JDK compilation environment

The aggregation project needs to be compiled together with related dependent projects during compilation, so some configuration needs to be done

  Specify the jdk compiled version of the current workspace

  Step 3: configure the item coding method in the workspace

  Parent project pom.xml file content

<?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>
    <!--Coordinates of the current project-->
    <groupId>com.jt</groupId>
    <artifactId>01-sca</artifactId>

    <version>1.0-SNAPSHOT</version>

    <!--Some students are creating maven Engineering time,There may be two sentences as follows,These two sentences are used to specify
    Of the current project jdk Compiled version and running version,It can also not be specified. We can pass it ourselves later maven Plug in configuration-->
    <!--
    <properties>
         <maven.compiler.source>8</maven.compiler.source>
         <maven.compiler.target>8</maven.compiler.target>
    </properties>
    -->
    <!--maven Parent project pom Sub modules are generally defined in the file,
    Management of dependent versions required in subprojects,Public dependent and parent project
    The packaging method is generally pom mode-->

    <!--First step: Define the version management of the core dependencies in the subproject(be careful,Just version management)-->
    <dependencyManagement>
        <dependencies>
            <!--spring boot Core dependent version definition(spring Official definition)-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.3.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!--Spring Cloud Microservice specification(from spring Official definition)-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR9</version>
                <type>pom</type><!--If scope yes import,type Must be pom-->
                <scope>import</scope><!--Introducing third-party dependent version design-->
            </dependency>

            <!--Spring Cloud alibaba Dependent version management (Refer to official instructions)-->
            <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>
    <!--Step 2: Add the required public dependencies of the subproject-->
    <dependencies>
        <!--lombok rely on,If necessary in the subproject lombok,No need to import-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope><!--provided Indicates that this dependency is only valid at compile time-->
        </dependency>
        <!--Unit test dependency,When unit test is required in subproject,There is no need to introduce this dependency again-->
         <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope><!--test Indicates that only test Use this dependency under the directory-->
            <exclusions>
                <exclusion><!--Eliminate unnecessary dependencies-->
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!--Other dependencies...-->
    </dependencies>
    <!--Step 3: Define the unified compilation and running version of the current project module and subproject-->
    <build><!--Project build configuration,We are based on maven Complete the compilation of the project,test,Packaging and other operations,
    All based on pom.xml Complete the operation of this column,However, the compiled and packaged configurations are written to build element
    Internal,The specific compilation and packaging configuration,Need again plugin To achieve,plugin Element is not required,maven
    There is a default plugin to configure,Common plug-ins can be viewed in the local library-->
        <plugins>
            <!--adopt maven-compiler-plugin Plug in settings item
            Unified jdk Compile and run versions-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                 <!--If the local library does not have this version,A red font error will appear here-->
                <version>3.8.1</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Design of service relationship and invocation relationship

  Realize the business and code practice process of a call link from the gateway to the service consumer, and then from the service consumer to the service provider.

Keywords: Java Spring Cloud Microservices

Added by Wayne Herbert on Mon, 29 Nov 2021 22:41:34 +0200