project-reactor

Spring Integration 5.0 + Project Reactor: controlling threads

蹲街弑〆低调 提交于 2019-12-10 18:08:21
问题 Followup question for https://stackoverflow.com/a/47136941/1776585 I can't make my integration handler to run in parallel threads while using Flux + split() + FluxMessageChannel . Consider the following snippet: // ... .handle(message -> Flux.range(0, 10) .doOnNext(i -> LOG.info("> " + i)) .subscribeOn(Schedulers.parallel())) .split() .channel(new FluxMessageChannel()) .handle(message -> LOG.info(" -> " + message.getPayload()))) // ... All logs are output in one thread: [ parallel-1] d.a

Spring Web Reactive Framework Multipart File Issue

若如初见. 提交于 2019-12-09 18:18:32
问题 I'm trying to implement and image upload using Spring's Reactive Framework by trying the following: @RestController @RequestMapping("/images") public class ImageController { @Autowired private IImageService imageService; @PostMapping(value = "", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) Mono<ImageEntity> saveImage(@RequestBody Mono<FilePart> part) throws Exception{ return part.flatMap(file -> imageService.saveImage(file)); } } But I keep

Flux not subscribing in Spring 5 reactor

ぐ巨炮叔叔 提交于 2019-12-09 13:26:53
问题 I'm probably missing something but I can't figure out what it is. The following code does nothing at all: webClient.get().uri("/some/path/here").retrieve() .bodyToMono(GetLocationsResponse.class) .doOnNext(System.out::println) .subscribe(); If I try to block the call it works fine: webClient.get().uri("/some/path/here").retrieve() .bodyToMono(GetLocationsResponse.class) .doOnNext(System.out::println) .block(); The weird thing is that if I create a Flux "manually" (i.e not coming from the

Spring Boot Webflux/Netty - Detect closed connection

可紊 提交于 2019-12-09 11:52:42
问题 I've been working with spring-boot 2.0.0.RC1 using the webflux starter ( spring-boot-starter-webflux ). I created a simple controller that returns a infinite flux. I would like that the Publisher only does its work if there is a client (Subscriber). Let's say I have a controller like this one: @RestController public class Demo { @GetMapping(value = "/") public Flux<String> getEvents(){ return Flux.create((FluxSink<String> sink) -> { while(!sink.isCancelled()){ // TODO e.g. fetch data from

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

北慕城南 提交于 2019-12-09 03:22:32
问题 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

Limiting rate of requests with Reactor

元气小坏坏 提交于 2019-12-08 20:20:31
I'm using project reactor to load data from a web service using rest. This is done in parallel with multiple threads. I'm starting to hit rate limits on the web service, so I would like to send at most 10 requests per second to avoid getting these errors. How would I do that using reactor? Using zipWith(Mono.delayMillis(100))? Or is there some better way? Thank you You can use delayElements instead of the whole zipwith . The code below will do a GET on https://www.google.com/ at a rate of 10 requests per second. You'll have to do additional changes in order to support the situation where your

How to delay repeated WebClient get request

旧街凉风 提交于 2019-12-08 11:03:15
问题 I am using the Spring 5 WebClient to repeatedly fetch some state of a running process from a REST api. With help from here I for now came to this solution: webClient.get().uri(...).retrieve.bodyToMono(State.class) .repeat() .skipUntil(state -> stateFinished()) .limitRequest(1) .subscribe(state -> {...}); While this works, the get request is fired at a very high rate. What would be the right way to limit the request rate to let's say 1 request per second? I tried using delayElements(Duration

How to use Reactor (Spring WebClient) to do a repeat call?

自闭症网瘾萝莉.ら 提交于 2019-12-08 07:53:30
问题 I am using Reactor (Spring5 WebClient) as my reactive programming API. I have 2 REST endpoint to call. The result of the first one will be the parameter to the second one. For the second API, it will return a result with "hasMore" value. If this value is true , I should change the pagination parameters and call the second API again. The demo code is the following: client.getApi1() .map(r -> r.getResult()) .flatMap(p -> client.getApi2(p, 2(page size), 1(page start))) .subscribe(r -> System.out

Limiting rate of requests with Reactor

安稳与你 提交于 2019-12-08 05:13:24
问题 I'm using project reactor to load data from a web service using rest. This is done in parallel with multiple threads. I'm starting to hit rate limits on the web service, so I would like to send at most 10 requests per second to avoid getting these errors. How would I do that using reactor? Using zipWith(Mono.delayMillis(100))? Or is there some better way? Thank you 回答1: You can use delayElements instead of the whole zipwith . 回答2: The code below will do a GET on https://www.google.com/ at a

Reactor Flux<MyObject> to Mono<List<MyObject>>

时光总嘲笑我的痴心妄想 提交于 2019-12-08 02:17:07
问题 How can I convert Flux<MyObject> directly to Mono<List<MyObject>> ? I am looking for equivalent of Single<List<MyObject>> single = observable.toList() from RxJava. With blocking operator I can do it like this: val just: Mono<List<MyObject>> = Mono.just(flux.toIterable().toList()) But it is executed at the time of declaration which doesn't seam to be right. 回答1: Flux has the method collectList() doing just the same like toList() in Rx. val just: Mono<List<MyObject>> = flux.collectList() 来源: