提问人:Libin 提问时间:9/2/2023 更新时间:9/2/2023 访问量:67
Spring reactive r2dbc - 如何以非阻塞方式循环返回 Flux<String>的第一个查询并调用返回 Flux<Object> 的第二个查询?
Spring reactive r2dbc - how to loop first query which returns Flux<String> and call second query which returns Flux<Object> in non blocking way?
问:
我不确定这是否可行。 我的第一个查询返回 Flux,我需要迭代它,以创建一个返回 Flux 的自定义查询,我的方法返回 Flux<Flux>
第一个查询
var tableNamesFlux = Mono.from(connectionFactory.create())
.flatMap((c) -> Mono.from(c.createStatement("show tables").execute()).doFinally((st) -> c.close()))
.flatMapMany(result -> Flux.from(result.map((row, meta)->
row.get(0, String.class)
)));
第二个查询
tableNamesFlux
.filter(name -> tablesNames.contains(name.toLowerCase()))
.map(name -> {
sql.append(name).append(" where <<conditions>>")
Mono.from(connectionFactory.create())
.flatMap((c) -> Mono.from(c.createStatement( sql.toString() )
.execute())
.doFinally((st) -> c.close()))
.flatMapMany(result -> Flux.from(result.map((row, meta) -> Object Mapping
响应
"scanAvailable": true,
"prefetch": -1
有人可以告诉我如何处理这种反应方式非阻塞吗?我仍在学习使用spring的响应式做事方式。
谢谢
答: 暂无答案
评论