Spring Boot 笔记 八 (分布式系统开发)

微服务(Microservice): 使用定义好边界的小的独立组件来做好一件事.

一, spring cloud

    spring cloud提供了config server, 它有在分布式系统开发中外部配置的功能.

   config server支持在git或在系统文件系统中放置文件,可以使用以下格式区分不同应用的不同配置文件:

    

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.xml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

     Spring Cloud提供注解@EnableConfigServer来启用配置服务

     

     Spring Cloud通过Netflix OSS的Eureka来实现服务发现,目的让每个服务之间互相通信

     服务端:@EnableEurekaServer; 客户端: @EnableEurekaClient

     1), 路由网关

     通过Zuul实现的, 提供@EnableZuulProxy来启用路由代理

     2), 负载均衡

     客户端: Ribbon和Feign

     在spring cloud下, 使用Ribbon直接注入一个RestTemplate对象即可

      使用Feign需定义一个注解,有@FeignClient注解的接口,然后用@RequestMapping映射远程Rest服务

     3), 断路器

      主要是解决当某个方法调用失败的时候,调用后备方案替代失败方法,达到容错,阻止级联错误功能

       @EnableCircuitBreaker 启动支持, @HystrixCommand的fallbackMethod来指定后备方案

       @EnableHystrixDashboard: 开启控制台来监控断路器的运行情况

    

猜你喜欢

转载自ldaolong.iteye.com/blog/2406012