Spring reactive r2dbc - how to loop first query which returns Flux<String> and call second query which returns Flux<Object> in non blocking way?

210 views Asked by At

I'm not sure if this is doable in reactive way. My first query returns Flux and I need to iterate it, to create a custom query which returns Flux and my method returns Flux<Flux>

First Query

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)
            )));

Second Query

     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

Response

"scanAvailable": true,
        "prefetch": -1

Can someone tell me how to handle this is reactive way non blocking? I'm still learning reactive way of doing things using spring.

Thanks

0

There are 0 answers