没有合适的资源?快使用搜索试试~ 我知道了~
首页微服务之Eureka服务注册中⼼
"第一代Spring Cloud核心组件:Eureka服务注册中心"
0 下载量 47 浏览量
更新于2023-11-22
评论
收藏 4.16MB PDF 举报
Spring Cloud Netflix是第一个Spring Cloud核心组件,其中包括Eureka服务注册中心、Ribbon负载均衡、Hystrix熔断器、Feign远程调用组件、Gateway网关组件和Config分布式配置中心。其中,Eureka服务注册中心是常用的服务注册中心之一,用于解耦服务提供者和服务消费者,支持服务提供者的弹性扩缩容特性。在分布式微服务架构中,服务注册中心存储着服务提供者的地址信息和相关属性信息,消费者通过查询和被动通知的方式获取服务提供者的地址信息,实现了透明化路由。因此,Eureka服务注册中心在微服务架构中扮演着重要角色。
资源详情
资源评论
资源推荐
4.在com.yx.eureka包下,创建EurekaApplication9201启动类,声明当前服务为Eureka注册中⼼。
5.修改yx-cloud-eureka-9200项⽬的application.yml⽂件,将defaultZone属性的值设置为向Eureka Server 9201
注册。
defaultZone: http://YXCloudEurekaServerA:9200/eureka
register-with-eureka: true # 表示是否向Eureka中⼼注册⾃⼰的信息,因为⾃⼰就是Eureka
Server所以不进⾏注册,默认为true
fetch-registry: true # 是否查询/拉取Eureka Server服务注册列表,默认为true
instance:
#hostname: localhost # 当前Eureka实例的主机名
# 使⽤ip注册,否则会使⽤主机名注册(此处考虑到对⽼版本的兼容,新版本经过实验都是ip)
prefer-ip-address: true
# ⾃定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address早期版本是ipAddress
instance-id: ${spring.cloud.client.ip-
address}:${spring.application.name}:${server.port}:@project.version@
package com.yx.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
// 声明本项⽬是⼀个Eureka Server
@EnableEurekaServer
@SpringBootApplication
public class EurekaApplication9201 {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication9201.class, args);
}
}
server:
port: 9200 # Eureka server服务端⼝
spring:
application:
name: yx-cloud-eureka # 应⽤名称,会在Eureka中作为服务的id标识
eureka:
client: # Eureka Server本身也是Eureka的⼀个客户端,因为在集群下需要与其他Eureka Server进⾏数据
的同步
service-url: # 客户端与Eureka Server交互的地址,如果是集群情况下defaultZone设置为集群下其他
的Eureka Server地址,多个地址使⽤","隔开
# defaultZone: http://localhost:9200/eureka
defaultZone: http://YXCloudEurekaServerB:9201/eureka
register-with-eureka: true # 表示是否向Eureka中⼼注册⾃⼰的信息,因为⾃⼰就是Eureka
Server所以不进⾏注册,默认为true
fetch-registry: true # 是否查询/拉取Eureka Server服务注册列表,默认为true
instance:
# hostname: localhost # 当前Eureka实例的主机名
6.在yx-service-product-9000项⽬的application.yml⽂件中修改defaultZone属性配置信息。
7.在yx-service-page项⽬的application.yml⽂件中修改defaultZone属性配置信息。
# 使⽤ip注册,否则会使⽤主机名注册(此处考虑到对⽼版本的兼容,新版本经过实验都是ip)
prefer-ip-address: true
# ⾃定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address早期版本是ipAddress
instance-id: ${spring.cloud.client.ip-
address}:${spring.application.name}:${server.port}:@project.version@
server:
port: 9000
spring:
application:
name: yx-service-product
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/yx_sc?
useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username: root
password: 123456
eureka:
client:
serviceUrl: # Eureka Server的路径
# defaultZone: http://localhost:9200/eureka/
defaultZone:
http://YXCloudEurekaServerA:9200/eureka,http://YXCloudEurekaServerB:9201/eureka
instance:
# 使⽤ip注册,否则会使⽤主机名注册(此处考虑到对⽼版本的兼容,新版本经过实验都是ip)
prefer-ip-address: true
# ⾃定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address早期版本是ipAddress
instance-id: ${spring.cloud.client.ip-
address}:${spring.application.name}:${server.port}:@project.version@
server:
port: 9100
spring:
application:
name: yx-service-page
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/yx_sc?
useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
username: root
password: 123456
eureka:
8.分别启动yx-cloud-eureka-9200和yx-cloud-eureka-9201服务,访问以下两个地址测试Eureka Server集群启动
情况。
2.4.3 重构服务消费者调⽤
1.启动yx-service-product-9000和yx-service-page项⽬,分别访问以下两个接⼝,测试查询接⼝数据是否正常。
client:
serviceUrl: # Eureka Server的路径
# defaultZone: http://localhost:9200/eureka/
defaultZone:
http://YXCloudEurekaServerA:9200/eureka,http://YXCloudEurekaServerB:9201/eureka
instance:
# 使⽤ip注册,否则会使⽤主机名注册(此处考虑到对⽼版本的兼容,新版本经过实验都是ip)
prefer-ip-address: true
# ⾃定义实例显示格式,加上版本号,便于多版本管理,注意是ip-address早期版本是ipAddress
instance-id: ${spring.cloud.client.ip-
address}:${spring.application.name}:${server.port}:@project.version@
http://yxcloudeurekaservera:9200/
http://yxcloudeurekaserverb:9201/
http://localhost:9000/product/query/1
http://localhost:9100/page/query/1
剩余73页未读,继续阅读
思绪千字难提
- 粉丝: 956
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0