- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有类似于以下示例的代码:
Mono<ResponseEntity<String>> result = webClient
.post()
.body(Mono.just(command), MyCommand.class)
.exchange()
.timeout(calculateTimeout(command))
.flatMap(clientResponse -> clientResponse.toEntity(String.class));
When using exchange() you must always use any of the body or toEntity methods of ClientResponse to ensure resources are released and to avoid potential issues with HTTP connection pooling. You can use bodyToMono(Void.class) if no response content is expected. However keep in mind that if the response does have content, the connection will be closed and will not be placed back in the pool.
问题:如果上面代码中的 timeout(...) 触发了 TimeoutException,我是否必须明确地做一些事情来确保所有资源都被正确释放或者上面的代码是否足够?我想避免在这里发生内存泄漏。
最佳答案
在这种情况下,我认为这不是问题。
触发时,timeout
将cancel()
上游,有效地关闭连接并且不将其返回到连接池。您不需要在这里做任何特别的事情,也不会有内存泄漏(除了已经位于 react 器内部队列中的缓冲区,这是 Spring Framework 将在 SPR-17025 中解决的问题)。
关于java - Spring WebFlux WebClient timeout() 和 exchange(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51937483/
我希望缓存Mono(仅在成功的情况下),这是WebClient调用的结果。 通过阅读项目 react 堆插件文档,我觉得CacheMono不太适合,因为它也存储了我不想要的错误。 因此,我没有使用Ca
我用 webflux 与 网易和 jdbc ,所以我以下一种方式包装阻塞 jdbc 操作: static Mono fromOne(Callable blockingOperation) {
有人可以告诉我或使用 提供现成的 CRUD 示例吗? WebFlux、RScoket 和 Spring(或 SpringBoot) ? 我研究了 RSocket 文档, WebFlux ,也写了我的简
我正在通过代理连接使用ssl服务测试webclient,但是使用安全ssl连接时出现以下错误。 你知道是什么问题吗? 堆栈跟踪: {"timestamp":"2019-10-29T18:35:43.5
public Mono filter(ServerWebExchange exchange, GatewayFilterChain chain) { Flux body = exchange.
我创建了一个过滤器,我可以在其中访问有效负载的主体并对其执行一些逻辑(现在假设我记录主体)。在最后一步中,我返回了 Mono,但是当请求通过 Controller 继续发送到服务时,它会抛出请求正文丢
上次我在考虑在我们的应用程序中正确使用记录器。例如,我有一个返回用户流的 Controller ,但在日志中,我看到“获取用户”日志正在被另一个线程而不是处理管道上的线程记录,但这是一个好方法吗? @
我正在使用带有 Netty 的 Spring Webflux (2.0.3.RELEASE) 并尝试了解服务器和 Web 客户端如何使用线程。我用 WebClient 编写了一些带有 http 调用链
我面临一个问题。我正在使用 Spring Webflux 并行调用一些 API。如果任何子线程面临任何问题,它需要记录请求。现在的问题是,用于记录一个普通的 POJO 类,其中有一个静态方法通过 Ap
我试图用 JSP 配置 Spring WebFlux。我在 Spring WebFlux 中没有看到任何支持 JSTL View 的 View 类。这是否意味着我们不能使用 Spring WebFlu
我正在寻找一种在响应式(Reactive) API 中使用计划任务的方法。 我知道它使用线程池,所以它与 webflux 组件不太兼容。 你有同等的人来做这项工作吗? 非常感谢 萨维留 最佳答案 有几
我曾经调用 HttpServletRequest.getRemoteAddr() 来获取客户端 ip。 我想知道如何通过 ServerWebExchange 获得它。 我最好的猜测是: serve
我想使用 spring webflux 以 react 方式流式传输文件。 我的端点应该看起来更具体什么是对象的类型? @GetMapping("/file") Flux file() { /
我无法让我的响应式(Reactive)代码以一种常见的方式处理错误。理想的方式是使用可重用的组件,我可以将其作为依赖项添加到其他项目中。 过去,我们使用 @RestControllerAdvise 通
我们正在尝试对 Webflux 使用react。我们将 Jaegar 与 Istio 用于检测目的。 Jaegar 非常了解 Spring MVC 端点,但似乎对 WebFlux 根本不起作用。 我正
我是响应式(Reactive)编程和 Spring WebFlux 的新手。我想让我的 App 1 通过 Flux 发布 Server Sent 事件,我的 App 2 持续监听它。 我希望 Flux
我正在我的项目中尝试新的 ReactiveQuerydslPredicateExecutor 但我找不到 findAll(Predicate, Pageable) 的方法,就像我在 QueryDslP
我正在使用 Spring WebFlux webclient 进行 REST 调用。我已经在 3000 上配置了连接超时毫秒,相应地: WebClient webClient = WebClient.
我想测量使用 WebFlux 进行的一些异步调用的长度。我一直在阅读各种来源,据我所知,@Timed 注释与 AspectJ 一起工作,基本上只是在方法调用之前启动一个计时器,然后停止它。这显然不适用
我有一个 Reactor Kafka 应用程序,它无限期地使用来自主题的消息。我需要公开一个健康检查 REST 端点,它可以指示此过程的健康状况——主要是想知道 Kafka 接收器通量序列是否已终止,
我是一名优秀的程序员,十分优秀!