问题标签 [spring-cloud-gateway]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
3998 浏览

spring-cloud - 如何为 Spring Cloud Gateway 中的每个路由设置超时?

有没有办法为 Spring Cloud Gateway 中的每个路由设置不同的超时值?例如 /route1 - 30s /route2 - 20s

0 投票
0 回答
359 浏览

project-reactor - 在 GatewayFilter 中处理 Mono.empty()

我正在构建一个 GatewayFilter,但在处理没有数据的情况时遇到了问题。以下是 GatewayFilterFactory<> 的示例:

这是getDataFromRedis方法:

它返回一个带有字符串值的 Mono,如果没有找到,则返回空。

上面的例子按预期工作,但是当redis的数据没有找到,并且返回了一个空的Mono,那么我需要它来返回一个重定向。所以这是我的尝试:

延迟的 mono inswitchIfEmpty总是被调用,不管 redis 中是否有数据。

总而言之,我需要过滤器添加从 Redis 获取的标头值,但如果没有可用数据则重定向。

0 投票
2 回答
1663 浏览

java - Spring Cloud Gateway 不适用于 @Bean DiscoveryClientRouteDefinitionLocator

我遵循 Spring Tips:Spring Cloud Gateway。但是我的网关应用程序不会从服务寄存器(Eureka)创建路由。具有 2 个参数的 DiscoveryClientRouteDefinitionLocator 构造函数。它不是从 Eureka 服务器路由的网关应用程序。我一直在尝试更改 pom.xml 中的版本,但我使用的是 RELEASE。

应用程序.java

DiscoveryClientRouteDefinitionLocator 的构造函数现在使用 2 个参数,而不是像 Spring Tips: Spring Clou Gateway 中的 1 个。

application.property:_

我的pom.xml

0 投票
0 回答
870 浏览

spring-boot - 如何禁用/配置位置标头的 Spring Cloud Gateway 重写

我们有一个 Spring Cloud Gateway 的设置,它运行 consul 服务发现并将请求代理到集群中的服务。

当这些服务之一以标头响应时,该Location: /标头会在通过网关的途中被重写。

问题是网关似乎添加了在 Consul 中找到的服务本地主机名和端口。这个 url 对客户端当然是不可用的(或不可取的)。

我已经验证了上游服务器发送: Location: /

(由“redirect:/”Spring MCV 简写生成)

但是当它到达最终客户端时被重写为: Location: https://10.0.0.10:34567/

https://10.0.0.10:34567/是 consul 中服务的上游位置)

如果当然是不正确的。

我的问题是我找不到任何关于如何配置它的文档,也没有说明使用了哪些类(用于调试),所以我只是不知道从哪里开始寻找修复程序。

期望的行为当然是保持重定向不变。

在这种特殊情况下,我们使用基于主机的路由设置:

任何帮助或提示表示赞赏。

0 投票
1 回答
5190 浏览

java - Spring Boot 使用 Cloud Gateway 和 Oauth2

我的问题是使用 Oauth2 的 Cloudgateway 安全性。但是,Oauth2 的配置@EnableOAuth2Sso会导致以下错误:

描述:

org.springframework.cloud.gateway.config.GatewayAutoConfiguration 中方法 modifyRequestBodyGatewayFilterFactory 的参数 0 需要找不到类型为“org.springframework.http.codec.ServerCodecConfigurer”的 bean。

行动:

考虑在你的配置中定义一个 'org.springframework.http.codec.ServerCodecConfigurer' 类型的 bean。

当我在 Eureka 上对 Zuul 代理执行相同操作时,一切正常。请帮助我如何解决这个问题。

这是 Cloudgateway 项目,我正在尝试使其成为 Oauth2 客户端:

配置:

应用程序.yml:

我通过授权码模型使用 Oauth2 服务器,参考这个问题

0 投票
1 回答
762 浏览

spring-cloud - 带有hystrix后备的spring-cloud-gateway,如何获取异常详细信息?

我已经配置了spring cloud gateway hystrix,如下所示:

问题是,例如,当我在项目中抛出 ResponseStatusException 异常时,将触发 hystrix 回退。

我想捕获一些错误信息并构建我的新 ApiErrorResponse,但我不知道该怎么做?

0 投票
0 回答
514 浏览

spring-cloud - How to log request and response body into database in spring cloud gateway?

I would like to log request and response body into database in spring cloud gateway. I am new at Spring Cloud Gateway and at Spring Webflux.

Could you please help about it?

0 投票
1 回答
5112 浏览

spring-webflux - 在 webflux 中读取请求正文

如何获取请求的主体,以便在 spring-webflux 中使用 spring 5 进行一些自定义判断?

0 投票
1 回答
3188 浏览

routes - Spring Cloud Gateway 自定义路由

我正在尝试使用 Spring Cloud Gateway 为以下场景定义路由:

http://gateway-url/service-url?token=foo_bar => 被转发到服务 url。

http://gateway-url/service-url => 被转发到其他地方

这就是我到目前为止所得到的。

这是我创建的过滤器

0 投票
1 回答
2044 浏览

spring-cloud - Spring Cloud Gateway 中的 Hystrix 命令

我正在使用 Spring cloud starter gateway 2.0.1.RELEASE 和 Starter netflix hystrix。是否可以在如下的路由定义中提供 HystrixCommand?

我的目标是在不将请求转发到后备 uri 的情况下执行后备方法。此外,我不能使用静态后备 uri 选项,因为我需要路径参数和请求参数来确定后备响应。任何帮助都非常感谢!