服务治理:Spring Cloud Eureka
核心内容:
1. 构建服务注册中心
2. 服务注册与服务发现
3. Eureka的基础架构
4. Eureka的服务治理机制
5. Eureka的配置
首先我们来搭建服务注册中心,需先创建一个Spring Boot项目,我的命名为eureka-server
1)接下来需在pom.xml文件引入必要的依赖内容
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.0.5.RELEASE
com.ml
eureka-server
eureka-server
Demo project for Spring Boot
1.8
Finchley.RELEASE
org.springframework.cloud
spring-cloud-starter-netflix-eureka-server
2.0.1.RELEASE
org.springframework.cloud
spring-cloud-dependencies
${ spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
注意:
在这里我希望跟大家说明一下,spring-boot、eureka-server以及spring-cloud的版本号对应非常重要,我也因为这个版本号的问题,因此在启动运行过程中遇到了好多的问题。
2)EurekaServerApplication.class文件需引入@EnableEurekaServer注解
作用:
用于启动服务注册中心提供给其他应用进行对话
@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
3)application.properties文件
#配置服务器端口
server.port=1111
spring.application.name=eureka-server
#指定主机名
eureka.instance.hostname=localhost
#是否向注册中心注册自己
eureka.client.register-with-eureka=false
#是否需要检索服务
eureka.client.fetch-registry=false
#注册中心地址
eureka.client.serviceurl.defaultZone=http://localhost:1111/eureka/
#是否开启自我保护机制
eureka.server.enable-self-preservation=true
#失效剔除时间间隔
eureka.server.eviction-interval-timer-in-ms=2000
以上就完成了一个简单的服务注册中心的搭建,接下来让我们来完成服务的注册与发现服务。
还没有评论,来说两句吧...