怎么用h5网站做动效,杭州网站推广,中元建设集团股份有限公司网站,如何快速进行网站开发Eureka 简介
Eureka 是一个基于 REST 的服务发现组件#xff0c;SpringCloud 将它集成在其子项目 spring-cloud-netflix 中#xff0c;以实现 SpringCloud 的服务注册与发现#xff0c;同时提供了负载均衡、故障转移等能力#xff0c;目前 Eureka2.0 已经不再维护#xf…Eureka 简介
Eureka 是一个基于 REST 的服务发现组件SpringCloud 将它集成在其子项目 spring-cloud-netflix 中以实现 SpringCloud 的服务注册与发现同时提供了负载均衡、故障转移等能力目前 Eureka2.0 已经不再维护故不推荐使用
Eureka 有两种角色组件
Eureka Server服务注册中心组件提供了服务的注册与发现的接口Eureka Client各种微服务把自身的服务实例注册到 Eureka Server 中也可通过 Eureka Server 获取服务列表消费服务
微服务客户端在 Eureka 上注册然后每隔 30 秒发送心跳来更新它们的租约。如果客户端不能多次续订租约就将在大约 90 秒内从服务器注册表中剔除。注册信息和更新被复制到集群中的所有 Eureka 节点来自任何区域的客户端都可以查找注册表信息每30秒发生一次来定位它们的服务并进行远程调用 搭建 Eureka 注册中心
创建 eureka-server 项目引入依赖本项目基于 SpringBoot 2.3.1SpringCloud Hoxton.SR12
dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependency...
dependencies在启动类上添加 EnaleEurekaServer 注解启用 Euerka 注册中心功能
EnableEurekaServer
SpringBootApplication
public class EurekaServerApplication {public static void main(String[] args) {SpringApplication.run(EurekaServerApplication.class, args);}
}在配置文件添加 Eureka 服务端的配置
server:port: 8001 # 指定运行端口spring:application:name: eureka-server # 指定服务名称eureka:instance:hostname: localhost # 指定主机名称client:fetch-registry: false # 指定能否从注册中心获取服务register-with-eureka: false # 指定是否将服务注册到注册中心运行 main 方法启动服务在浏览器中访问 http://localhost:8001/ 便可以看到 Eureka 注册中心的界面
创建 eureka-client 项目引入依赖
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId
/dependencydependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId
/dependency在启动类上添加 EnableDiscoveryClient 注解表明是一个 Eureka 客户端
EnableDiscoveryClient
SpringBootApplication
public class EurekaClientApplication {public static void main(String[] args) {SpringApplication.run(EurekaClientApplication.class, args);}
}在配置文件添加 Eureka 客户端的配置
server:port: 8101 # 指定运行端口spring:application:name: eureka-client # 指定服务名称eureka:client:fetch-registry: true # 指定能否从注册中心获取服务register-with-eureka: true # 指定是否将服务注册到注册中心service-url:defaultZone: http://localhost:8001/eureka运行 main 方法启动 eureka-client 项目刷新 http://localhost:8001/ 页面即可看到 cureka-client 已经注入 Eurcka 服务 搭建 Eureka 注册中心集群
由于所有服务都会注册到注册中心服务之间的调用都是通过从注册中心获取服务列表来调用的。注册中心一旦宕机所有服务调用都会出现问题因此需要多个注册中心组成集群来提供服务
创建两个 eureka-server 项目eureka-server-1 项目的配置文件如下
server:port: 8002 # 指定运行端口spring:application:name: eureka-server-1 # 指定服务名称eureka:instance:hostname: localhost # 指定主机名称client:fetch-registry: true # 指定能否从注册中心获取服务register-with-eureka: true # 指定是否将服务注册到注册中心service-url:defaultZone: http://localhost:8003/eureka/eureka-server-2 项目的配置文件如下
server:port: 8003 # 指定运行端口spring:application:name: eureka-server-1 # 指定服务名称eureka:instance:hostname: localhost # 指定主机名称client:fetch-registry: true # 指定能否从注册中心获取服务register-with-eureka: true # 指定是否将服务注册到注册中心service-url:defaultZone: http://localhost:8002/eureka/通过两个注册中心互相注册搭建注册中心的双节点集群。分别启动项目查看 http://localhost:8001/ 和 http://localhost:8002/可以看到两个注册中心已经分别注册了