我正在尝试使用webflux将json字符串发送到put端点。
例如,假设我试图到达的终点是http://etc:99999/put/here,我的代码如下所示:
@Service
public class someService {
private final WebClient webClient;
public someService(WebClient.Builder webClientBuilder) {
this.webClient = webClientBuilder.baseUrl("http://etc:9999999/").build();
}
public Mono<Void> sendPut(String someMessage) {
return webClient.put()
.uri("put/here")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(someMessage)
.retrieve();
}
}然而,这似乎根本没有触及端点。我做错了什么?
发布于 2021-06-19 04:03:56
问题是没有任何东西订阅我的web客户端。即
Mono<void> putStream = webClient.put()
.uri("put/here")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(someMessage)
.retrieve()
.bodyToMono();不会发送put请求。
但是-
Mono<void> putStream = webClient.put()
.uri("put/here")
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(someMessage)
.retrieve()
.bodyToMono();
putStream.subscribe();将要。
下面是Reactor文档中帮助我解决这个问题的相关部分:Reactor Docs。
https://stackoverflow.com/questions/68039756
复制相似问题