系列目录:spring
本文基于SpringCloud-Dalston.SR5缓存
Eureka做为服务注册中心对整个微服务架构起着最核心的整合做用,所以对Eureka仍是有很大的必要进行深刻研究。安全
Eureka 1.x版本是纯基于servlet的应用。为了与spring cloud结合使用,除了自己eureka代码,还有个粘合模块spring-cloud-netflix-eureka-server。在咱们启动EurekaServer实例的时候,只用加入对于spring-cloud-starter-eureka-server的依赖便可。以后经过@EnableEurekaServer注解便可启动一个Eureka服务器实例。服务器
其官方文档中对本身的定义是:网络
Spring Cloud Netflix provides Netflix OSS integrations for Spring Boot apps through autoconfiguration and binding to the Spring Environment and other Spring programming model idioms. With a few simple annotations you can quickly enable and configure the common patterns inside your application and build large distributed systems with battle-tested Netflix components. The patterns provided include Service Discovery (Eureka), Circuit Breaker (Hystrix), Intelligent Routing (Zuul) and Client Side Load Balancing (Ribbon)..架构
Spring Cloud Netflix这个项目对于Spring Boot应用来讲,它集成了NetFlix OSS的一些组件,只需经过注解配置和Spring环境的通用简单的使用注解,你能够快速的启用和配置这些久经测试考验的NetFlix的组件于你的应用和用于构建分布式系统中。这些组件包含的功能有服务发现(Eureka),熔断器(Hystrix),智能路由(Zuul)以及客户端的负载均衡器(Ribbon) 简单的来讲,Spring Cloud NetFlix这个项目对NetFlix中一些久经考验靠谱的服务发现,熔断,网关,智能路由,以及负载均衡等作了封装,并经过注解的或简单配置的方式提供给Spring Cloud用户用。app
Eureka is a REST (Representational State Transfer) based service that is primarily used in the AWS cloud for locating services for the purpose of load balancing and failover of middle-tier servers. We call this service, the Eureka Server. Eureka also comes with a Java-based client component,the Eureka Client, which makes interactions with the service much easier. The client also has a built-in load balancer that does basic round-robin load balancing. At Netflix, a much more sophisticated load balancer wraps Eureka to provide weighted load balancing based on several factors like traffic, resource usage, error conditions etc to provide superior resiliency.负载均衡
简单来讲Eureka就是Netflix开源的一款提供服务注册和发现的产品,而且提供了相应的Java客户端。分布式
其实有点不太同样,Spring Cloud Netflix提供的胶水代码更换了一些初始化配置,而且去掉了一些不合理的例如单实例EurekaServer服务等待时间,还增长了更人性化的界面:ide
从设计思路上看,Eureka是AP型设计,ZOOKEEPER是CP型设计:
综上所述,Eureka适合做为服务注册发现中心,Zookeeper适合更普遍的分布式协调服务
比较细节的架构图以下所示,以后的文章咱们会详细解释:
注意,这个和官网的不同,在SpringCloud环境下,context-path就是eureka
header 1 | header 2 |
---|---|
row 1 col 1 | row 1 col 2 |
row 2 col 1 | row 2 col 2 |
Operation | HTTP action(针对SpringCloudNetflix环境下启动的Eureka) | Description |
---|---|---|
注册新服务实例或者修改实例基本信息(就是InstanceInfo类) | POST /eureka/apps/appID | Input:JSON/XMLpayload HTTPCode: 204 on success |
撤销删除服务实例 | DELETE /eureka/apps/appID/instanceID | HTTP Code: 200 on success |
实例心跳 | PUT /eureka/apps/appID/instanceID | HTTP Code:* 200 on success * 404 ifinstanceIDdoesn’t exist |
查询全部服务实例列表 | GET /eureka/apps | HTTP Code: 200 on success Output:JSON/XML |
查询某个服务的实例列表 | GET /eureka/apps/appID | HTTP Code: 200 on success Output:JSON/XML |
查询某个服务某个实例信息 | GET /eureka/apps/appID/instanceID | HTTP Code: 200 on success Output:JSON/XML |
查询某个实例信息 | GET /eureka/instances/instanceID | HTTP Code: 200 on success Output:JSON/XML |
将某个实例设置为下线,这个和删除不一样,若是你手动调用删除,但若是客户端还活着,定时任务仍是会将实例注册上去。可是改为这个状态,定时任务更新不了这个状态 | PUT /eureka/apps/appID/instanceID/status?value=OUT_OF_SERVICE | HTTP Code:* 200 on success * 500 on failure |
下线状态恢复 | DELETE /eureka/apps/appID/instanceID/status?value=UP (The value=UP is optional, it is used as a suggestion for the fallback status due to removal of the override) | HTTP Code:* 200 on success * 500 on failure |
更新元数据(这个不是InstanceInfo,是本身能够往里面自定义的数据) | PUT /eureka/apps/appID/instanceID/metadata?key=value | HTTP Code: * 200 on success * 500 on failure |
查询某个VIP下的全部实例 | GET /eureka/vips/vipAddress | * HTTP Code: 200 on success Output:JSON/XML * 404 if thevipAddressdoes not exist. |
查询某个SVIP下的全部实例 | GET /eureka/svips/svipAddress | * HTTP Code: 200 on success Output:JSON/XML * 404 if thesvipAddressdoes not exist. |
下一篇,咱们会详细分析Eureka一些流程