SpringCloud (first day)

1. The single application: all resources in an application, packaged as a war package, a Tomcat run, run in one process.

a) Solution: You can do a cluster, but is not convenient local extension (separate clusters for one module), maintenance, development, upgrade trouble, a single technology selection, selection of a single database

2. Micro services: a system of multiple small services, each focused on a business each service has its own processes, data exchange between micro services through a network communication protocol (. Usually delivered using HTTP restFul style )

a) Advantage: diversified technology selection, database selection diversified, easy to maintain, easy to do local development, each service has a separate process

b)  Dubbo和SpringCloud

            I.     Dubbo the RPC communication protocol (TCP-based communication)

           II.     SpringCloud HTTP communication protocol of TCP in a package, in terms of performance with respect to low Dubbo

3.SpringCloud

a) micro-Services

b) Maven build multi-module environment.

  i. a parent project to build a module

  1. Pom.xml 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>cn.itsource</groupId>
        <artifactId>springboot-parent</artifactId>
        <packaging>pom</packaging>
        <version>1.0-SNAPSHOT</version>
        <modules>
    //父项目的各个子模块项目 <module>springboot-eureka</module> <module>springboot-userclient</module> <module>springboot-deptprovider</module> </modules> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Finchley.SR1</spring-cloud.version> <springboot.version>2.0.5.RELEASE</springboot.version> </properties> <!--版本依赖管理工具--> <dependencyManagement> <dependencies> <!--springboot版本控制--> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!--springCloud版本控制--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${springboot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>

        ii. registry server environment to build

  1. Package guide pom.xml
    <dependencies>
        <!--springboot支持-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--Eureka服务端支持-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    // spring-cloud-starter-netflix-eureka-server包含了spring-cloud-starter-netflix-eureka-client包
        </dependency>
    </dependencies>
  2. Application.yml profile configuration
    the Spring: 
      the Application: 
        name: the Spring -cloud- Eureka 
    Server: 
      Port: 7001 
    Eureka: 
      instance: 
        hostname: localhost 
      Client: # is not registered with the Eureka own 
        the Register
         the -with-Eureka: false 
        # Do not check other EurekaServer node 
        FETCH -registry: false 
        service - url: 
          # set address eureka server is located, tracking and registration procedures are registered to this address (the address of the service exposure) 
          defaultzone: HTTP: // $ {eureka.instance.hostname}: $ {} server.port / eureka /
  3. Registry service startup class
    @SpringBootApplication
    @EnableEurekaServer
    public class SpringBootApplicationConfig_7001 {
        public static void main(String[] args) {
            SpringApplication.run(SpringBootApplicationConfig_7001.class,args);
        }
    }

    iii. Consumers and providers to build the client environment

  1. Pom.xml
<dependencies>
    <!--springboot支持-->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!--Eureka服务端支持-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
</dependencies>

   2.Application.yml profile configuration

the Spring: 
  the Application: 
    name: SPRING -CLOUD- the USER 
Server: 
  Port: 8001 
eureka: 
  instance: 
    hostname: localhost 
  Client: 
    Service - url: 
      # Set address eureka server is located, tracking and registration procedures are registered to this address (service exposed address) 
      #defaultZone: HTTP: // $ {} eureka.instance.hostname: the server.port} {$ / Eureka / 
      defaultzone: HTTP: // localhost: 7001 / Eureka

 


       3. Register to the registry: Client service startup class

@SpringBootApplication
@EnableEurekaClient
public class SpringbootApplication_8001 {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootApplication_8001.class,args);
    }
}

If there is more than one service, you set up multiple sub-modules in the parent module below, do the same configuration service registration to the registry.

Guess you like

Origin www.cnblogs.com/8888-lhb/p/11546458.html