Julywhj 2019-12-15
在这里插入图片描述
Registery:表示服务向注册中心注册。
Renew:表示服务向注册中心发送心跳,表示该服务还活着,注册中心不能删除改服务。
Cancel:表示注册中心能删除该服务
Get Registery:表示该服务重新注册
Replicate:表示注册中心之间相互注册
Remote Call:表示远程调用
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <!--基本信息--> <description>SpringBoot-Eureka环境搭建多模块构建示例</description> <modelVersion>4.0.0</modelVersion> <name>eureka-father</name> <packaging>pom</packaging> <!-- 项目说明:这里作为聚合工程的父工程 --> <groupId>com.org.ldc</groupId> <artifactId>eureka-father</artifactId> <version>1.0.0.RELEASE</version> <!-- 继承说明:这里继承SpringBoot提供的父工程 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.2.RELEASE</version> </parent> <!-- 表示子模块 --> <modules> <module>eureka3000</module> </modules> <!-- 子模块的依赖 --> <dependencyManagement> <dependencies> <dependency> <groupId>com.org.ldc</groupId> <artifactId>eureka3000</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> </dependencies> </dependencyManagement></project>
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.org.ldc</groupId> <artifactId>eureka3000</artifactId> <version>0.0.1-SNAPSHOT</version> <name>eureka3000</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <!-- 继承本项目的父工程 --> <parent> <groupId>com.org.ldc</groupId> <artifactId>eureka-father</artifactId> <version>1.0.0.RELEASE</version> </parent> <!--引入eurekaserver 依赖--> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </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>Finchley.SR2</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></project>
package com.org.ldc.eureka3000;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication@EnableEurekaServerpublic class Eureka3000Application { public static void main(String[] args) { SpringApplication.run(Eureka3000Application.class, args); }}
server: port: 3000eureka: server: enable-self-preservation: false #关闭自我保护机制 eviction-interval-timer-in-ms: 4000 #设置清理间隔(单位:毫秒 默认是60*1000) instance: hostname: localhost client: registerWithEureka: false #不把自己作为一个客户端注册到自己身上 fetchRegistry: false #不需要从服务端获取注册信息(因为在这里自己就是服务端,而且已经禁用自己注册了) serviceUrl: defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.org.ldc</groupId> <artifactId>user5000</artifactId> <version>0.0.1-SNAPSHOT</version> <name>user5000</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <!-- 继承本项目的父工程 --> <parent> <groupId>com.org.ldc</groupId> <artifactId>eureka-father</artifactId> <version>1.0.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </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>Finchley.SR2</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></project>
server: port: 5000eureka: client: serviceUrl: defaultZone: http://localhost:3000/eureka/ #eureka服务端提供的注册地址 参考服务端配置的这个路径 instance: instance-id: user-1 #此实例注册到eureka服务端的唯一的实例ID prefer-ip-address: true #是否显示IP地址 leaseRenewalIntervalInSeconds: 10 #eureka客户需要多长时间发送心跳给eureka服务器,表明它仍然活着,默认为30 秒 (与下面配置的单位都是秒) leaseExpirationDurationInSeconds: 30 #Eureka服务器在接收到实例的最后一次发出的心跳后,需要等待多久才可以将此实例删除,默认为90秒spring: application: name: server-user #此实例注册到eureka服务端的name
package com.org.ldc.user5000;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication@EnableEurekaClient //开启eureka客户端public class User5000Application { public static void main(String[] args) { SpringApplication.run(User5000Application.class, args); }}
更多的教程请关注公众号 非科班的科班,。假如你觉得我写的好,路过的请点个赞,谢谢。