czb1n

不是谁的谁,在乎你是你

0%

简介

  • SpringCloudGatewaySpringCloudZuul一样是微服务网关,不过Gateway是SpringCloud官方推出的,而Zuul是Netflix推出的。
    看其他人的一些文章说是Gateway是用于取代Zuul的第二代网关,这个我在官方找不到资料说明。

  • 主要术语

    • Route: 路由。
    • Predicate: 断言,即匹配规则。
    • Filter: 过滤器,用于修改请求。

Route: Route the basic building block of the gateway. It is defined by an ID, a destination URI, a collection of predicates and a collection of filters. A route is matched if aggregate predicate is true.

Predicate: This is a Java 8 Function Predicate. The input type is a Spring Framework ServerWebExchange. This allows developers to match on anything from the HTTP request, such as headers or parameters.

Filter: These are instances Spring Framework GatewayFilter constructed in with a specific factory. Here, requests and responses can be modified before or after sending the downstream request.

  • 功能实现流程
    image

以下示例均基于SpringCloud的Greenwich.SR1版本,且需要依赖到之前介绍SpringCloud相关的文章

阅读全文 »

简介

  • SpringCloudConfig是一个集中性、动态的、可拓展的配置服务,并且提供多种存储配置内容的方式,为微服务架构中的其他应用提供配置。

支持存储方式:

  • Git Backend
  • File System Backend
  • Vault Backend
  • JDBC Backend
  • Redis Backend
  • CredHub Backend

配置文件的命名格式:

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

application 为配置中的spring.config.name 即项目名称。
profile为spring.cloud.config.profile 指定的配置类型。
label为一个git中的可选字段,默认为master

以下示例均基于SpringCloud的Greenwich.SR1版本,且需要依赖到之前介绍SpringCloud相关的文章

阅读全文 »

简介

  • 什么是服务网关?
    实现统一入口,接收所有的请求,并根据定义的规则转发到相应的服务上。
    在此过程中还可以完成系统中一些通用统一的工作,如权限校验,限流等。

  • Zuul就是NetFlix提供的一个服务网关,用于实现路由、过滤器等功能。

Netflix uses Zuul for the following:

  • Authentication
  • Insights
  • Stress Testing
  • Canary Testing
  • Dynamic Routing
  • Service Migration
  • Load Shedding
  • Security
  • Static Response handling
  • Active/Active traffic management

以下示例均基于SpringCloud的Greenwich.SR1版本,且需要依赖到之前介绍SpringCloud相关的文章

阅读全文 »

简介

  • 什么是负载均衡?
    负载均衡是分布式架构中不可或缺的一个组件,其意义在于通过一定的规则或者算法去将请求分摊到各个服务提供者。

  • Ribbon是一个客户端的负载均衡器,它提供一系列让你控制HTTP和TCP客户端的能力。

以下示例均基于SpringCloud的Greenwich.SR1版本,且需要依赖到之前介绍Eureka的文章

阅读全文 »

简介

  • 什么是断路器?
    断路器就是为了解决微服务架构中的“雪崩”现象,即某个服务出现问题会导致其他服务阻塞,严重最终会导致服务器瘫痪。
    当服务出现问题是,断路器会负责断开这个该服务的依赖,以防止问题蔓延,保护整体服务。

  • Hystrix也是SpringCloudNetflix微服务套件中的一个组件,作为断路器的角色。

image

以下示例均基于SpringCloud的Greenwich.SR1版本。

阅读全文 »

简介

  • EurekaSpringCloudNetflix微服务套件中的一个组件。

负责服务的注册和发现。其中包含EurekaServer为服务端,即服务注册中心。以及EurekaClient,即各个注册的微服务。
Eureka支持高可用的配置,支持自动保护模式,允许故障期间继续提供服务。

以下示例均基于SpringCloud的Greenwich.SR1版本。

阅读全文 »