最近在学习Spring WebFlux。当我尝试关闭连接池中的连接时,它不起作用!
代码是这样的:
return connectionPool.create().flatMap(connection -> {
Mono<Result> result = Mono.from(connection.createStatement("").execute());
connection.close();
return result;
})
.flatMap(body -> Mono.from(body.map(((row, rowMetadata) -> row.get(0, String.class)))));
我注意到该close
函数会返回一个Publish< Void>
对象,但我不知道如何一起处理两个数据流(Mono< Result>
和Publish< Void>
)!
有人可以帮助我吗?
您可以将doFinally()
处理程序附加到 ,Mono
以便它可以确保连接关闭,无论流处理是否正常完成。
像这样的东西:
.flatMap(c ->
Mono.from(c.createStatement("query goes here...")
.execute())
.doFinally((st) -> close(c))
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句