简体   繁体   中英

How to collect data after Flux.subscribe to send it as a json array?

This is an example that I made it, what should I do to get the treated data to send the result list as a WS json response ?

    @Produces(MediaType.APPLICATION_JSON)
     public List<String> tryFlux(@QueryParam("names") List<String> names) {
         String[] array = new String[names.size()];
         Flux.fromIterable(asList(names.toArray(array))).
                 doOnNext(this::executeService).doOnError(ex -> handleError(ex, names)).retry(1).subscribe();
         return ??; //Need help here
      }

You can wrap already resolved values with Mono to return JSON data.

  @Produces(MediaType.APPLICATION_JSON)
 public Mono<JSONResponseObject> tryFlux(@QueryParam("names") List<String> names) {
     String[] array = new String[names.size()];
     Flux.fromIterable(asList(names.toArray(array))).
             doOnNext(this::executeService).doOnError(ex -> handleError(ex, names)).retry(1).subscribe();
     return Mono.just(jsonResponseObject); //Need help here
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM