【发布时间】:2020-12-30 19:54:56
【问题描述】:
我正在尝试使用 JAVA web-flux 创建一个 POST API。在此 API 中,我想创建一个字符串列表并进行数据库调用以获取 Mono<List> 作为响应,但是当我尝试使用 block() 将 Mono<List> 转换为简单列表对象时,我得到以下响应:
{
"code": 500,
"message": "block()/blockFirst()/blockLast() are blocking, which is not supported in thread reactor-http-nio-8"
}
如何将 Mono 对象转换为简单的 List 对象?
我正在使用以下代码:
List<String> paymentInstrumentIdList = paymentInstrumentRequest.getPaymentInstruments().stream().map(PaymentInstrumentData::getPaymentInstrumentId).collect(Collectors.toList());
Mono<List<PaymentInstrument>> paymentInstrumentList = paymentInstrumentRepository.getByPartitionKey(partitionKey.toString(), DocType.PAYMENT_INSTRUMENT, paymentInstrumentIdList);
return ResponseEntity.ok(responseMapper.getResponseAsClass(graphQlQueryController.queryPaymentInstrumentsByPaymentInstrumentId(baseHeaders, personId, membershipId, paymentInstrumentList.block()), Wallet.class, "Wallet"));
【问题讨论】:
标签: java lambda reactive-programming spring-webflux