Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Spring cloud (3): the Construction of Eureka Service

Shulou Source: shulou.com Published: 2022-06-03 05:21:46 10月02日 Update

1. Concept: Eureka-Cloud Service Discovery, a REST-based service for locating services to enable cloud middle-tier service discovery and failover.

2. Build: a. First of all, let's talk about building a stand-alone machine. Create a new maven project, and import the coordinates of eureka in pom:

Org.springframework.boot

Spring-boot-starter-parent

1.4.0.RELEASE

Org.springframework.cloud

Spring-cloud-starter-eureka-server

B. Create a new class EurekaApplication

@ SpringBootApplication

@ EnableEurekaServer

Public class EurekaApplication {

Public static void main (String [] args) {

SpringApplication.run (EurekaApplication.class, args)

}

}

Among them, @ EnableEurekaServer starts a service registry to provide dialogue to other applications.

C, configuration items of application.properties

# default port server.port=8761

Eureka.client.register-with-eureka=false

Eureka.client.fetch-registry=false

Eureka.client.serviceUrl.defaultZone= http://localhost:${server.port}/eureka/

D. Start springboot and visit http://localhost:8761/

3. The above is only a stand-alone environment, and the commercial environment is often a highly available (HA) environment. At this time, we have to consider the cluster. One node is dead, and there is another node. We just need to change the configuration file for the cluster.

Eureka.client.serviceUrl.defaultZone= http://localhost:8762/eureka/;http://localhost:8763/eureka/; if the ip is different and three nodes are configured, three machines are required

Tags: Service environment node configuration cloud stand-alone cluster different three middle tier just commercial coordinate location service fault file time machine concept mode Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker MariaDB OPPO Reno Apple