一、Eureka架构介绍
Eureka是Netflix开发的服务发现组件,本身是一个基于REST的服务。
Spring Cloud将它集成在其子项目spring-cloud-netflix中,以实现Spring Cloud的服务发现功能服务发现组件对比(CAP)Zookeeper - CPEureka - APEureka
他的源码在github上面:https://github.com/Netflix/eureka/
他的文档:https://github.com/Netflix/eureka/wiki
他的架构介绍:High level architecture:https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance
二、服务器端:
加入spring cloud父POM及spring-cloud-starter-eureka-server
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
Application.properties:
server.port=8761
#取消向eureka server(注册中心)注册
eureka.client.register-with-eureka=false
#取消向eureka server(注册中心)获取注册信息
eureka.client.fetch-registry=false
#eureka 提供服务发现的地址
eureka.client.service-url.defaultZone=http://localhost:8761/eureka
启动类增加注解@EnableEurekaServer
三、微服务端
加入spring cloud父POM及spring-cloud-starter-eureka
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<!-- eureka -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
Application.properties:
eureka.client.serviceUrl.defaultZone=http://zhangfei:777@localhost:8761/eureka
eureka.instance.prefer-ip-address=true
eureka.instance.instance-id=${spring.application.name}:${spring.application.instance_id:${server.port}}
启动类增加注解@EnableEurekaClient