在前面的很多章节中,有讨论到关于微服务架构的相关话题,包括服务网关、服务发现、服务熔断等相关话题,本章我们就借助Spring Cloud相关组件,来实现微服务一些基础架构的搭建与应用。
本章涉及的Spring Cloud相关组件包含如下:
- Config Server:配置中心
- Eureka Server:服务注册中心
- Zuul Api Gateway:服务网关
- Hystrix:服务熔断
- Spring Boot Admin:服务监控与管理
- Feign Client:服务调用
下图是基础架构图
服务监控
通过Spring Boot Admin监控我们所有的服务运行状态
支持动态修改日志级别
服务网关
对外统一服务地址:
http://zuul_ip:zuul_port/service-id/route_path
比如,我们访问地址:
http://localhost:8009/config-client/find/999
其实就是访问服务config-client的接口:
http://localhost:8889/find/999
服务调用与熔断
通过使用声明式Rest客户端FeignClient,我们可以简化微服务间的服务调用,同时通过指定fallback支持Hystrix服务熔断
@FeignClient(value = "config-server", fallback = FindServiceHystrix.class)
正常调用结果:
find Hello 999! from config server
服务不可用返回结果:
find oops, config server down for hello server 999