

微服务网关Zuul迁移到Spring Cloud Gateway
source link: http://blueskykong.com/2018/09/20/integration-enhanced/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

在之前的文章中,我们介绍过微服务网关 Spring Cloud Netflix Zuul ,前段时间有两篇文章专门介绍了Spring Cloud的全新项目Spring Cloud Gateway,以及其中的过滤器工厂。本文将会介绍将微服务网关由Zuul迁移到Spring Cloud Gateway。
Spring Cloud Netflix Zuul是由Netflix开源的API网关,在微服务架构下,网关作为对外的门户,实现动态路由、监控、授权、安全、调度等功能。
Zuul基于servlet 2.5(使用3.x),使用阻塞API。 它不支持任何长连接,如websockets。而Gateway建立在Spring Framework 5,Project Reactor和Spring Boot 2之上,使用非阻塞API。 Websockets得到支持,并且由于它与Spring紧密集成,所以将会是一个更好的开发体验。
在一个微服务集成的项目中 microservice-integration ,我们整合了包括网关、auth权限服务和backend服务。提供了一套微服务架构下,网关服务路由、鉴权和授权认证的项目案例。整个项目的架构图如下:
具体参见: 微服务架构中整合网关、权限服务 。本文将以该项目中的Zuul网关升级作为示例。
Zuul网关
在该项目中,Zuul网关的主要功能为路由转发、鉴权授权和安全访问等功能。
Zuul中,很容易配置动态路由转发,如:
zuul: ribbon: eager-load: enabled: true #zuul饥饿加载 host: maxTotalConnections: 200 maxPerRouteConnections: 20 routes: user: path: /user/** ignoredPatterns: /consul serviceId: user sensitiveHeaders: Cookie,Set-Cookie
默认情况下,Zuul在请求路由时,会过滤HTTP请求头信息中的一些敏感信息,这里我们不过多介绍。
网关中还配置了请求的鉴权,结合Auth服务,通过Zuul自带的Pre过滤器可以实现该功能。当然还可以利用Post过滤器对请求结果进行适配和修改等操作。
除此之外,还可以配置限流过滤器和断路器,下文中将会增加实现这部分功能。
迁移到Spring Cloud Gateway
笔者新建了一个 gateway-enhanced
的项目,因为变化很大,不适合在之前的 gateway
项目基础上修改。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK