Spring Cloud Eureka 注册与发现操作步骤详解

时间:2021-05-20

在搭建Spring Cloud Eureka环境前先要了解整个架构的组成,常用的基础模式如下图:


服务提供者:将springboot服务编写好以后,通过配置注册中心地址方式注册,提供给消费者使用。
注册中心:服务的中间桥梁,服务提供者将服务注册。服务消费者可以通过注册信息调用需要使用的服务。
服务消费者:通过规定的调用方式,读取注册中心的注册信息,调用相应的服务。

根据后续的服务复杂度进化以后,可以看到服务提供者也可以是服务消费者,服务消费者也可以是服务提供者。根据不同的业务情况是可以互相调用的。

下面来搭建一个基础的eureka。环境还是使用的之前的spring官方下载的。

内容写的比较详细,可以跟这一步步操作。

一、注册中心



以下是几个需要修改和添加的地方,后面会有完整的pom.xml

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.3.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <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><!-- 最新版的 eureka 服务端包 --> <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-actuator</artifactId> </dependency> Spring Cloud Spring Boot Angel版本 兼容Spring Boot 1.2.x Brixton版本 兼容Spring Boot 1.3.x,也兼容Spring Boot 1.4.x Camden版本 兼容Spring Boot 1.4.x,也兼容Spring Boot 1.5.x Dalston版本、Edgware版本 兼容Spring Boot 1.5.x,不兼容Spring Boot 2.0.x Finchley版本 兼容Spring Boot 2.0.x,不兼容Spring Boot 1.5.x Greenwich版本 兼容Spring Boot 2.1.x

这里采用Finchley.SR2版本 springboot版本改成 2.1.3.RELEASE

完整的pom.xml

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://monRequest

返回服务提供者的 hello方法参数。

整个最简单的过程就完成了,需要更好的使用spring cloud 后续需要了解分布式、负载均衡、熔断等概念。在后续章节将一步步的拆分。

到此这篇关于Spring Cloud Eureka 注册与发现操作步骤详解的文章就介绍到这了,更多相关Spring Cloud Eureka 注册内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章