怎么查询网站所有关键词,美术馆网站的建设流程,wordpress侧面小工具,wordpress能不能做商城可以将Spring Cloud Gateway视为Spring Cloud Netflix Zuul项目的后续产品#xff0c;并有助于在微服务环境中实现Gateway模式 。 它建立在 Spring Boot 2和Spring Webflux端到端都是无阻塞的-它公开了一个基于Netty的服务器#xff0c;使用基于Netty的客户端进行下游微服务… 可以将Spring Cloud Gateway视为Spring Cloud Netflix Zuul项目的后续产品并有助于在微服务环境中实现Gateway模式 。 它建立在 Spring Boot 2和Spring Webflux端到端都是无阻塞的-它公开了一个基于Netty的服务器使用基于Netty的客户端进行下游微服务调用并在其余流程中使用了反应堆核心 。 我的目的是演示如何使用Spring Cloud Gateway以多种方式转换基于Spring Cloud Netflix Zuul的小型路由。 Spring Cloud Netflix Zuul Spring Cloud Zuul允许使用此处表示为yaml的属性文件来配置简单的路由规则 zuul:routes:sample:path: /zuul/**url: http://httpbin.org:80strip-prefix: true 该路由将在Zuul中暴露一个终结点该终结点将拦截对前缀为“ / zuul”的uri的任何请求并在去除“ zuul”前缀后将其转发至下游系统。 Spring Cloud Gateway Spring Cloud Gateway允许以三种方式对等效功能进行编码-使用基于Java的DSL使用基于Kotlin的DSL和使用基于简单属性的配置。 可以使用出色的http://start.spring.io网站生成一个入门项目 基于Java的DSL 以下是创建类似于Zuul路由的基于Java的dsl import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;Configuration
public class GatewayRoutes {Beanpublic RouteLocator routeLocator(RouteLocatorBuilder builder) {return builder.routes().route(r -r.path(/java/**).filters(f - f.stripPrefix(1)).uri(http://httpbin.org:80)).build();}} 这是可读的DSL它配置一条路由该路由以“ java”为前缀拦截uri并在去除该前缀后将其发送到下游系统。 基于Kotlin的DSL 基于Kotlin的DSL配置此路由如下所示。 import org.springframework.cloud.gateway.route.RouteLocator
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.gateway.route.builder.filters
import org.springframework.cloud.gateway.route.builder.routes
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ConfigurationConfiguration
class KotlinRoutes {Beanfun kotlinBasedRoutes(routeLocatorBuilder: RouteLocatorBuilder): RouteLocator routeLocatorBuilder.routes {route { path(/kotlin/**)filters { stripPrefix(1) }uri(http://httpbin.org)}}
} 我最初为Spring Cloud Gateway路由提交了基于Kotlin的DSL的PR 因此偏向于使用Kotlin配置Spring Cloud Gateway :-)。 该路由采用前缀为“ kotlin”的URL并在进行下游微服务调用之前将其剥离。 物业路线 最后是基于属性的属性 spring:cloud:gateway:routes: - predicates:- Path/props/**filters:- StripPrefix1uri: http://httpbin.org 像Java和Kotlin版本一样此路由使用带有前缀“ props”的url并在进行下游调用之前将其删除。 基于属性的版本具有在运行时可刷新的附加优点。 结论 通过比较Spring Cloud Netflix Zuul的典型配置如何映射到Spring Cloud Gateway这是Spring Cloud Gateway的快速入门。 翻译自: https://www.javacodegeeks.com/2018/04/spring-cloud-gateway-configuring-a-simple-route.html