通过 spring `WebClient` 进行 api 调用但忽略结果的正确方法是什么?
What is the proper way to make an api call via springs `WebClient`, but ignore the result?
通过弹簧 WebClient
进行 api 调用但忽略结果的正确方法是什么? ClientResponse
对象特别指出我必须对结果做一些事情...
NOTE: When given access to a ClientResponse, through the WebClient exchange() method, you must always use one of the body or toEntity methods to ensure resources are released and 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.
我可以调用 WebClient 并忽略结果吗?或者是否有一个通用的包罗万象的 "body or toEntity method" 我可以使用然后忽略?
在 Spring Framework 5.2 之前,使用 WebClient#exchange()
方法并直接处理 Mono<ClientResponse>
可能会非常复杂或导致潜在的内存泄漏。
从 Spring Framework 5.2 开始,这对开发人员来说变得更加容易,并且 exchange()
方法已被弃用。
Mono<ResponseEntity<Void>> response = webClient.put()
.uri("https://example.org/book/123")
.retrieve()
.toBodilessEntity();
Spring 将读取响应主体(如果存在)并释放数据缓冲区,然后 return 连接到池。它确保没有内存泄漏,包括在使用额外的 Reactor 运算符时。
通过弹簧 WebClient
进行 api 调用但忽略结果的正确方法是什么? ClientResponse
对象特别指出我必须对结果做一些事情...
NOTE: When given access to a ClientResponse, through the WebClient exchange() method, you must always use one of the body or toEntity methods to ensure resources are released and 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.
我可以调用 WebClient 并忽略结果吗?或者是否有一个通用的包罗万象的 "body or toEntity method" 我可以使用然后忽略?
在 Spring Framework 5.2 之前,使用 WebClient#exchange()
方法并直接处理 Mono<ClientResponse>
可能会非常复杂或导致潜在的内存泄漏。
从 Spring Framework 5.2 开始,这对开发人员来说变得更加容易,并且 exchange()
方法已被弃用。
Mono<ResponseEntity<Void>> response = webClient.put()
.uri("https://example.org/book/123")
.retrieve()
.toBodilessEntity();
Spring 将读取响应主体(如果存在)并释放数据缓冲区,然后 return 连接到池。它确保没有内存泄漏,包括在使用额外的 Reactor 运算符时。