我是反应式编程的新手。有人可以解释一下,调用mono.subscribe或任何数据处理管道处理程序时会发生什么情况?我从文档中了解到,反压概念是指消费端能够接收多少数据。但是我的问题是关于处理程序的异步执行。当某些数据由发布者发布时,如何调用订阅?处理程序如何从堆栈中读取变量?
void makeHttpRequest(MyRequest myRequest, String endpoint) {
SomeOtherObject some = getSomeData();
myWebClient.post()
.uri(URI.create(endpoint))
.body(Mono.just(myRequest), MyRequest.class)
.exchange()
.flatMap(clientResponse -> {
return clientResponse.bodyToMono(MyResponse.class);
})
.map(resp -> {
Map<String, Object> data = new HashMap<>();
data.put("request", myRequest);// I can access myRequest. But how?
data.put("response", resp);
data.put("more", some);// same question as myRequest
return data;
})
.subscribe(data -> {
MyRequest req = data.get("request");
MyResponse resp = data.get("response");
})
}