Spring Boot integrates Spring Cloud to realize microservice architecture learning (1)

       When you see this, a warm reminder: Before learning springcloud, please learn springboot first, because springcloud is based on springboot.

Microservice Architecture

What is Microservice Architecture?

Architecture design concepts , isolation between services (distribution is also isolation), autonomy (distribution depends on the overall combination) and other features (single responsibility, boundary, asynchronous communication, independent deployment) are the strict implementation of the distributed concept

Evolution from SOA to Microservice Architecture

Function: Each service can be applied independently, and the combined service can also be applied systematically (simplified implementation strategy of monolith application - platform idea)

What is the difference between SOA architecture and microservice architecture?

The SOA architecture is mainly aimed at the enterprise level, using ESB services (ESB enterprise service bus), which is very heavy, requires serialization and deserialization, and is transmitted in XML format.

The microservice architecture is mainly used by Internet companies. It is lightweight, small, and runs independently. It is transmitted based on Http+Rest+JSON format.

What is springcloud?

        SpringCloud provides developers with some tools to quickly build distributed systems, including configuration management, service discovery, circuit breakers, routing, load balancing , micro-agents, event buses, global locks, decision campaigns, distributed sessions, and more. It runs in a simple environment and can run on the developer's computer.

Service provider and consumer relationship

Service Provider: Provides a service to be called by someone

Consumer: call to be serviced

The organizational structure of springcloud is as follows:


That's it for a simple introduction. If you don't understand, you can visit the official link of springcloud: http://projects.spring.io/spring-cloud/.


Then let's start to build a springcloud environment based on springboot:

1: First build the springboot cloud registration center

In order to discover and manage multiple springboot applications, the eureka service can be used. Just add @EnableEurekaServer to the startup class. Also add configuration files. The eureka registry will wait for the application to actively register with it, and after discovering a new application, the eureka registry will continue to send a heartbeat to the application to determine whether it is alive , and periodically send a heartbeat packet to the registry to inform it of its survival condition.

1.1 Create a maven project: as shown


1.2 Import the required dependencies into Pom

<parent>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-parent</artifactId>

<version>1.5.2.RELEASE</version>

<relativePath /><!-- lookup parent from repository --> 

</parent>

<properties>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<java.version>1.8</java.version>

</properties>

 

<dependencies>

<!--eureka server -->

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-eureka-server</artifactId>

</dependency>

<!-- spring boot test -->

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-test</artifactId>

<scope>test</scope>

</dependency>

</dependencies>

<dependencyManagement>

<dependencies>

<dependency>

<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-dependencies</artifactId>

<version>Dalston.RC1</version>

<type>pom</type>

<scope>import</scope>

</dependency>

</dependencies>

</dependencyManagement>

<build>

<plugins>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

</plugins>

</build>

<repositories>

<repository>

<id>spring-milestones</id>

<name>Spring Milestones</name>

<url>https://repo.spring.io/milestone</url>

<snapshots>

<enabled>false</enabled>

</snapshots>

</repository>

</repositories>

1.2 Placement application.yml

server:

  port: 8888

eureka:

  instance:

    hostname: localhost

  client:

    registerWithEureka:false 

    fetchRegistry : false 

    serviceUrl :

      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

1.3 Start EurekaServer

@SpringBootApplication

@EnableEurekaServer

publicclass App { 

publicstaticvoid main(String[] args) {  

SpringApplication.run(App.class, args);

}

}


After running, just enter http:localhost:8888.


Guess you like

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