background

In 2019, the first blog intends to start from the micro service, is the so-called their own flag lie lie also want to finish writing ^^. So I plan to continue writing spring-Cloud articles from today.

What are microservices

  1. Microservices are an architectural style
  2. A series of tiny services
  3. Each service is developed and deployed independently

Why microservices are used

Because there are some problems in the use of monomer, it is summarized as follows:

  1. Low development efficiency (large code system)
  2. Difficult code maintenance (large code system)
  3. Poor stability (changing one module may affect other code functions)
  4. Expansion difficulty (single module extension needs to consider whether it affects other module functions)
  5. Inflexible deployment (long deployment time and cumbersome deployment)

What is the Eureka

  1. Eureka: As the name suggests, Eureka’s role in Spring-Cloud is registration and discovery of services
  2. Spring Cloud Eureka is a secondary encapsulation based on Netflix Eureka
  3. The Spring Cloud Eureka component consists of two parts: Eureka-Server and Eureka-client
  4. Eureka-server: service registry
  5. Eureka-client: service registration and service invocation

instructions

  1. In the series of blogs, the version of Spring-Cloud is Greenwich.RC1
  2. IDE USES the idea of
  3. Spring-boot version :2.1.1.RELEASE. We can go to the official website to check the corresponding spring-Cloud version and Boot version

Set up Eureka – Server

  1. Open IDEA and select Create Spring project

  2. Select Maven coordinate: GAv

  3. Select eureka-Server as the project type

  4. After creating the project, check the Spring-Cloud and Boot versions in the Pom:

<! -- Spring-boot version -->
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.1. RELEASE</version>
    <relativePath/> <! -- lookup parent from repository -->
</parent>

<! -- Spring-cloud version -->
<properties>
    <java.version>1.8</java.version>
    <spring-cloud.version>Greenwich.RC1</spring-cloud.version>
</properties>
Copy the code
  1. As eureka-server we need to add the @enableEurekaserver annotation to the startup class
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
    public static void main(String[] args) { SpringApplication.run(EurekaServerApplication.class, args); }}Copy the code
  1. Modifying configuration files
  1. Since bootstrap.yml/properties in Spring-Cloud (yML in this case) is the startup load configuration file for the project, we first rename the configuration file to bootstrap.yml
  1. As a service registry, we require high reliability and stability, so we set up three sets of Eureka-Servers with ports 8761, 8762 and 8763 respectively. The project construction method is the same (same as above). The configuration file of Eureka-Server1 is as follows:
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8762/eureka/,http://localhost:8763/eureka/
    register-with-eureka: false

spring:
  application:
    name: eureka-server

server:
  port: 8761
Copy the code

The configuration files of Eureka-server2 are as follows:

spring:
  application:
    name: eureka-server2

server:
  port: 8762

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/,http://localhost:8763/eureka/
    register-with-eureka: false
Copy the code

The configuration files of Eureka-server3 are as follows:

spring:
  application:
    name: eureka-server3

server:
  port: 8763

eureka:
  client:
    register-with-eureka: false
    service-url:
      defaultZone: http://localhost:8761/eureka/,http://localhost:8762/eureka/
Copy the code

Configuration description:

  1. Spring.application. name: is the name of the service
  2. Server. port: indicates the service port
  3. Register-with-eureka =false Indicates that the eureka-server does not need to register itself
  4. As can be seen from the configuration of the three Eureka-Servers above, in the registered Eureka-server cluster, we only need to register different Eureka-servers with each other to realize the high availability of Eureka-Server
  1. After starting the service, we can access :http://localhost:8761/; http://localhost:8762/; http://localhost:8763/ Found that the registry is started:

At the end

Now that our clustered Eureka-Server is set up, let’s set up eureka-Client to discover services in the next section. Well, how to predict the future, please listen to the next decomposition!