我正在尝试使用 JAVA web-flux 创建一个 POST API。在此 API 中,我想创建一个字符串列表并进行数据库调用以获取 df <- structure(list(col1 = c(1L, NA, NA, NA), col2 = c(3L, 1L, NA,
NA), col3 = c(NA, 6L, 1L, NA)), class = "data.frame", row.names = c(NA,
-4L))
作为响应,但是当我尝试使用 Mono<List>
将 Mono<List>
转换为简单列表对象时,我'我得到以下回复:
block()
如何将 Mono 对象转换为简单的 List 对象?
我正在使用以下代码:
{
"code": 500,
"message": "block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-8"
}
答案 0 :(得分:2)
webflux 应用程序的全部目的是您无法阻止
您正在寻找的是 flatMap
函数。
return paymentInstrumentRepository.getByPartitionKey(
partitionKey.toString(),
DocType.PAYMENT_INSTRUMENT, paymentInstrumentIdList)
.flatmap(list -> {
return return ServerResponse.ok().body(responseMapper.getResponseAsClass(
graphQlQueryController.queryPaymentInstrumentsByPaymentInstrumentId(
baseHeaders,
personId,
membershipId,
list);
};
这是 webflux 的基本知识,我建议您阅读 official reactor documentation getting started 以了解基础知识和目的。
答案写在手机上,未经测试。
这里还有一个 getting started tutorial