SpringCloud detailed analysis (1)

SpringCloud API:
https://springcloud.cc/spring-cloud-dalston.html#spring-cloud-ribbon

SpringCloud Chinese website:
https://springcloud.cc/

Chinese documentation of SpringCloud components:
https://springcloud.cc/spring-cloud-netflix.html

What is a microservice architecture?

1

Generally speaking, a microservice architect is an architectural pattern or architectural style. He advocates dividing a single program into a set of small services, each of which runs in its own process, and the services coordinate with each other. , cooperate with each other to provide users with the ultimate value. Services communicate with each other using lightweight communication mechanisms (usually HTTP-based RESTful APIs). Each service is built around a specific business and can be independently deployed to production environments, production-like environments, etc. In addition, a unified, centralized service management mechanism should be avoided as much as possible. For specific services, the appropriate language should be selected according to the context, and the tools should be constructed for it. There can be a very lightweight centralized management and coordination of these services, and services can be written in different languages. data storage.

2

From a technical point of view, the core of microservices is to divide a unified one-stop application into individual services according to specific businesses, and completely decouple them. Each microservice provides a single business function service. When a service does one thing, it is actually an independent processing process, similar to the concept of a process, which can be started and destroyed independently, and has its own independent database.

Microservices

In the microservice eclipse tool, there are independent small modules developed by maven. It specifically uses a small module developed by SpringBoot. Professional things are handed over to professional modules. One module does one thing, and the emphasis is on a Each individual completes a specific function or task.

>

In general microservices are a subset of microservices architecture

Advantages and disadvantages of microservices

Advantages: Each service is cohesive enough, small enough, and the code is easy to understand. This can focus on a specified business function and business requirements, the development is simple, the development efficiency is high, a service can concentrate on only one thing, microservices It can be developed independently by a small team. A small team of 2-5 people is a loosely coupled, functionally meaningful service. It is independent in both the development phase and the deployment phase. Microservices are developed in different languages.
Easy to integrate with third parties, microservices allow an easy and flexible way to integrate automatic deployment, through continuous integration tools, such as jenkins, Hudson, bamboo, microservices are easy to be understood, developed, modified and maintained by a developer, so that small teams can be more Pay attention to the fruits of your own labor, and you don't need to cooperate to reflect the value.
Microservices allow the use of the latest technologies.
Microservices are just code for business logic, not combined with HTML, CSS or other interface tools.
Each microservice has its own storage capability, it can have its own independent database or the same database,

>

Disadvantages:
Developers need to deal with the complexity of distributed systems,
the difficulty of multi-service operation and maintenance, increasing with the increase of services,
system deployment dependencies,
data consistency,
system integration testing,
performance monitoring

Microservice technology stack

Meaning: a collection of various technologies

write picture description here

write picture description here

What is SpringCloud?

SpringCloud: A set of microservice solutions based on SpringBoot, including service registration and discovery, configuration center, full-link monitoring, service gateway, load balancing, and circuit breaker components, in addition to the highly abstract encapsulation of NetFlix-based open source components, There are also some option-neutral open source components.
SpringCloud is to use the convenience of SpringBoot development to ingeniously simplify the development of distributed system infrastructure. SpringCloud provides developers with some tools to quickly build distributed systems, including configuration management, service discovery, circuit breakers, routing, micro-proxy, event bus , global locks, decision competition, distributed sessions, etc., it can be started and deployed with one click in the SpringBoot development style.

The relationship between SpringBoot and SpringCloud

SpringBoot focuses on the rapid and convenient development of a single individual service

>

SpringCloud is a global microservice coordination and governance framework. It integrates and manages the single services developed by SpringBoot to provide services between various microservices, configuration management service discovery, circuit breakers, routers, microagents, and event buses. , global locks, decision competition, distributed sessions and other integration services.

>

Springboot can leave SpringCloud separate development projects, but SpringCloud cannot do without SpringBoot

>

SpringBoot focuses on the rapid and convenient development of single services, and SpringCloud focuses on the global service governance framework.

Microservices: Case 1
Building Four Projects

 microserverecloud  整体父工程  有自公共子模块所需的jar包等提取出来其他的自工程不用再导入jar包
 microserverecloud-api 公共子模块  提供其他的子模块都要使用的entity或者都要使用的方法
 microserverecloud-provider-dept  服务提供者
 microservercloud-consumer-dept  服务消费者

microserverecloud overall parent project:
provide jar package: pay attention to the pom.xml file

 注意点:
 1 <packaging>pom</packaging> 聚合项目

 子模块
 2 <modules>
    <module>../microserverecloudapi</module>
    <module>../microserverecloudproviderdept</module>
    <module>../microservercloudconsumerdept</module>
   </modules>
<?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>yiche.com</groupId>
  <artifactId>microserverecloud</artifactId>
  <version>1.0-SNAPSHOT</version>
  <!--注意:父工程师pom工程-->
  <packaging>pom</packaging>

  <name>microserverecloud Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <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>
  </properties>


  <parent>

    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.6.RELEASE</version>
  </parent>



  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>

    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>



  </dependencies>


  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Dalston.SR1</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <modules>
    <module>../microserverecloudapi</module>
    <module>../microserverecloudproviderdept</module>
    <module>../microservercloudconsumerdept</module>
   </modules>

  <build>
    <finalName>microserverecloud</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.20.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

microserverecloud-api public submodule:

Entity class exists for calling

public class Employee implements Serializable{

 private Integer id;
 private String name;
 private Double salary;
 private Integer age;
 private String dbName; //子工程使用的数据库,因为每个微服务可以使用自己的数据库

}

pom文件:
<?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">
    <parent>
        <artifactId>microserverecloud</artifactId>
        <groupId>yiche.com</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../microserverecloud/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <groupId>yiche.com.cc</groupId>
    <artifactId>microserverecloud-api</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>microserverecloud-api</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>


    <dependencies>



    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

microserverecloud-provider-dept service provider
pom file:

Note: This method calls the public entity class or method yiche.com.cc microserverecloud-api ${project.version}







<?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">
    <parent>
        <artifactId>microserverecloud</artifactId>
        <groupId>yiche.com</groupId>
        <version>1.0-SNAPSHOT</version>
        <relativePath>../microserverecloud/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

     <groupId>yiche.com</groupId>
    <artifactId>microserverecloud-provider-dept</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>microserverecloud-provider-dept</name>
    <!-- FIXME change it to the project's website -->
    <url>http://www.example.com</url>


    <dependencies>
        <!--在这里要引用公共自工程的资源 比如说employee实体类  或者非法-->
        <dependency>
             <!--公共子模块的groupId-->
            <groupId>yiche.com.cc</groupId>
            <!--公共子模块的artifactId-->
            <artifactId>microserverecloud-api</artifactId>
            <version>${project.version}</version>
        </dependency>

    </dependencies>

    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <artifactId>maven-clean-plugin</artifactId>
                    <version>3.0.0</version>
                </plugin>
                <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
                <plugin>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                </plugin>
                <plugin>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.20.1</version>
                </plugin>
                <plugin>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
                </plugin>
                <plugin>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <version>2.8.2</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

The microservercloud-consumer-dept service consumer is the same as the service provider
Note :

 <!--在这里要引用公共自工程的资源 比如说employee实体类  或者非法-->
        <dependency>
             <!--公共子模块的groupId-->
            <groupId>yiche.com.cc</groupId>
            <!--公共子模块的artifactId-->
            <artifactId>microserverecloud-api</artifactId>
            <version>${project.version}</version>
        </dependency>

Guess you like

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