project-reactor

Why Spring ReactiveMongoRepository does't have save method for Mono?

↘锁芯ラ 提交于 2019-12-01 11:04:30
I have a MovieRepository which extended ReactiveMongoRepository. I want to save a single POJO in a reactive way. But ReactiveMongoRepository doesn't provide save method for Mono or Publisher. I have to use block() method or use the saveAll method in the ReactiveMongoRepository. public Mono<ServerResponse> create(ServerRequest request) { Mono<Movie> movieMono = request.bodyToMono(Movie.class); return movieRepository.save(movieMono.block()) // .flatMap((movie) -> ServerResponse.ok().body(fromObject(movie))); } Is there a better way to solve this kind of problem? I don't think use block method is

block()/blockFirst()/blockLast() are blocking error when calling bodyToMono AFTER exchange()

删除回忆录丶 提交于 2019-12-01 09:17:29
I am trying to use Webflux to stream a generated file to another location, however, if the generation of the file ran into an error, the api returns success, but with a DTO detailing the errors while generating the file instead of the file itself. This is using a very old and poorly designed api so please excuse the use of post and the api design. The response from the api call (exchange()) is a ClientResponse. From here I can either convert to a ByteArrayResource using bodyToMono which can be streamed to a file, or, if there is an error in creating the file, then I can convert to the DTO also

How to create a Spring Reactor Flux from a ActiveMQ queue?

青春壹個敷衍的年華 提交于 2019-12-01 03:16:01
I am experimenting with the Spring Reactor 3 components and Spring Integration to create a reactive stream (Flux) from a JMS queue. I am attempting to create a reactive stream (Spring Reactor 3 Flux) from a JMS queue (ActiveMQ using Spring Integration) for clients to get the JMS messages asynchronously. I believe that I have everything hooked up correctly but the client does not receive any of the JMS messages until the server is stopped. Then all of the messages get "pushed" to the client a once. Any help would be appreciated. Here is the configuration file that I am using to configure the

How to create a Spring Reactor Flux from a ActiveMQ queue?

五迷三道 提交于 2019-12-01 00:24:30
问题 I am experimenting with the Spring Reactor 3 components and Spring Integration to create a reactive stream (Flux) from a JMS queue. I am attempting to create a reactive stream (Spring Reactor 3 Flux) from a JMS queue (ActiveMQ using Spring Integration) for clients to get the JMS messages asynchronously. I believe that I have everything hooked up correctly but the client does not receive any of the JMS messages until the server is stopped. Then all of the messages get "pushed" to the client a

Cache the result of a Mono from a WebClient call in a Spring WebFlux web application

拈花ヽ惹草 提交于 2019-11-30 18:11:15
问题 I am looking to cache a Mono (only if it is successful) which is the result of a WebClient call. From reading the project reactor addons docs I don't feel that CacheMono is a good fit as it caches the errors as well which I do not want. So instead of using CacheMono I am doing the below: Cache<MyRequestObject, Mono<MyResponseObject>> myCaffeineCache = Caffeine.newBuilder() .maximumSize(100) .expireAfterWrite(Duration.ofSeconds(60)) .build(); MyRequestObject myRequestObject = ...; Mono

How to collect paginated API responses using spring boot WebClient?

荒凉一梦 提交于 2019-11-30 16:03:40
I have a paginated response from an URL, I want to keep on hitting the next page URL which I get from the previous response and keep on collecting items till I don't have a "nextPage" URL in my response. How to achieve this in a reactive way using spring boot WebClient from WebFlux with out blocking? Request1: GET /items response: { items: [...] nextPage: "/items?page=2" } Request2: GET /items?page=2 response: { items: [...] nextPage: "/items?page=3" } Request3: GET /items?page=3 response: { items: [...] nextPage: null } Here I have created mock urls https://karthikdivi.com/apps

How to execute blocking calls within a Spring Webflux / Reactor Netty web application

半世苍凉 提交于 2019-11-30 15:34:31
问题 In my use case where I have a Spring Webflux microservice with Reactor Netty, I have the following dependencies: org.springframework.boot.spring-boot-starter-webflux (2.0.1.RELEASE) org.springframework.boot.spring-boot-starter-data-mongodb-reactive (2.0.1.RELEASE) org.projectreactor.reactor-spring (1.0.1.RELEASE) For a very specific case I need to retrieve some information from my Mongo database, and process this into query parameters send with my reactive WebClient . As the WebClient nor the

How to execute blocking calls within a Spring Webflux / Reactor Netty web application

偶尔善良 提交于 2019-11-30 14:17:34
In my use case where I have a Spring Webflux microservice with Reactor Netty, I have the following dependencies: org.springframework.boot.spring-boot-starter-webflux (2.0.1.RELEASE) org.springframework.boot.spring-boot-starter-data-mongodb-reactive (2.0.1.RELEASE) org.projectreactor.reactor-spring (1.0.1.RELEASE) For a very specific case I need to retrieve some information from my Mongo database, and process this into query parameters send with my reactive WebClient . As the WebClient nor the UriComponentsBuilder accepts a Publisher (Mono / Flux) I used a #block() call to receive the results.

Is it possible to start Mono's in parallel and aggregate the result

别说谁变了你拦得住时间么 提交于 2019-11-30 09:07:21
I know it is possible to chain Mono's, for ex,... Mono<String> resultAMono = loadA(); Mono<String> resultBMono = resultA.flatMap(resultA -> loadB()); This will chain and resultBMono will run when resultAMono returns.... So my question is, is it possible to start 2 Mono's in parallel and when both returns continue with another Mono? I think it will look something like this... Mono<String> resultAMono = loadA(); Mono<String> resuktBMono = loadB(); Mono<Tuple2<Stirng, String> tupleMono = Mono.zip(resultAMono, resultBMono); but I have no idea this will run in Parallel or what can I do this to run

ParallelFlux vs flatMap() for a Blocking I/O task

删除回忆录丶 提交于 2019-11-30 06:50:32
I have a Project Reactor chain which includes a blocking task (a network call, we need to wait for response). I'd like to run multiple blocking tasks concurrently. It seems like either ParallelFlux or flatMap() could be used, bare-bone examples: Flux.just(1) .repeat(10) .parallel(3) .runOn(Schedulers.elastic()) .doOnNext(i -> blockingTask()) .sequential() .subscribe() or Flux.just(1) .repeat(10) .flatMap(i -> Mono.fromCallable(() -> {blockingTask(); return i;}).subscribeOn(Schedulers.elastic()), 3) .subscribe(); What are the merits of the two techniques? Is one to be preferred over the other?