1

有人可以提供一个例子并解释如何使用这种方法吗?我是 Reactor 项目的新手,我很难理解使用它的方式,而且那里似乎没有足够的教程。我想要的是调用一个服务,它将以字符串格式返回一个主机名,然后我想将其作为 uri 用户

这是方法的包和方法:

org.springframework.cloud.gateway.route.builder



/**
 * A filter which change the URI the request will be routed to by the Gateway.
 * @param determineRequestUri a {@link Function} which takes a
 * {@link ServerWebExchange} and returns a URI to route the request to
 * @return a {@link GatewayFilterSpec} that can be used to apply additional filters
 */
public GatewayFilterSpec changeRequestUri(Function<ServerWebExchange, Optional<URI>> determineRequestUri) {
    return filter(new AbstractChangeRequestUriGatewayFilterFactory<Object>(Object.class) {
        @Override
        protected Optional<URI> determineRequestUri(ServerWebExchange exchange, Object config) {
            return determineRequestUri.apply(exchange);
        }
    }.apply(c -> {
    }));
}
4

0 回答 0