project-reactor

Spring WebClient: How to stream large byte[] to file?

放肆的年华 提交于 2020-07-31 12:13:00
问题 It seems like it the Spring RestTemplate isn't able to stream a response directly to file without buffering it all in memory. What is the proper to achieve this using the newer Spring 5 WebClient ? WebClient client = WebClient.create("https://example.com"); client.get().uri(".../{name}", name).accept(MediaType.APPLICATION_OCTET_STREAM) ....? I see people have found a few workarounds/hacks to this issue with RestTemplate , but I am more interested in doing it the proper way with the WebClient

What is a good idiom for nested flatMaps in Java Reactor?

眉间皱痕 提交于 2020-07-21 04:21:29
问题 I inherited responsibility for a REST service written in Java using Spring and associated libraries including Reactor. For expensive operations like REST calls out or database operations the code is extensively wrapping the results in Reactor Mono. There are all sorts of things that need to be addressed in the code but one that keeps showing up is nested flatMap s over Mono s for sequences of expensive operations that end up up indented several levels deep into an unreadable mess. I find it

What is a good idiom for nested flatMaps in Java Reactor?

瘦欲@ 提交于 2020-07-21 04:21:02
问题 I inherited responsibility for a REST service written in Java using Spring and associated libraries including Reactor. For expensive operations like REST calls out or database operations the code is extensively wrapping the results in Reactor Mono. There are all sorts of things that need to be addressed in the code but one that keeps showing up is nested flatMap s over Mono s for sequences of expensive operations that end up up indented several levels deep into an unreadable mess. I find it

Are subscribers in Spring Reactor unbounded by default?

北战南征 提交于 2020-07-15 08:47:39
问题 I've been working in Spring Reactor and had some previous testing that made me wonder how Fluxes handle backpressure by default. I know that onBackpressureBuffer and such exist, and I have also read that RxJava defaults to unbounded until you define whether to buffer, drop, etc. So, can anyone clarify for me: What is the default backpressure behavior for a Flux in Reactor 3? I tried searching for the answer but didn't find any clear answers, only definitions of Backpressure or that answer

Are subscribers in Spring Reactor unbounded by default?

只愿长相守 提交于 2020-07-15 08:47:13
问题 I've been working in Spring Reactor and had some previous testing that made me wonder how Fluxes handle backpressure by default. I know that onBackpressureBuffer and such exist, and I have also read that RxJava defaults to unbounded until you define whether to buffer, drop, etc. So, can anyone clarify for me: What is the default backpressure behavior for a Flux in Reactor 3? I tried searching for the answer but didn't find any clear answers, only definitions of Backpressure or that answer

Why does Thread.sleep() trigger the subscription to Flux.interval()?

一个人想着一个人 提交于 2020-06-27 16:59:08
问题 If, in a main() method, I execute this Flux.just(1,2) .log() .subscribe(); I get this in the console: [ INFO] (main) | onSubscribe([Synchronous Fuseable] FluxArray.ArraySubscription) [ INFO] (main) | request(unbounded) [ INFO] (main) | onNext(1) [ INFO] (main) | onNext(2) [ INFO] (main) | onComplete() If instead of just() I use the interval() method: Flux.interval(Duration.ofMillis(100)) .take(2) .log() .subscribe(); the elements are not logged, unless I add Thread.sleep() which gives me: [

who calls subscribe on Flux or Mono in reactive webapplication

喜欢而已 提交于 2020-06-22 03:19:10
问题 I am looking at some examples of reactive web applications and i am seeing them like this @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public Mono<Person> findById(...) { return exampleService.findById(...); } @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseBody public Flux<Person> findAll() { Flux<Person> persons = exampleService.findAll(); return persons; } When i am reading about the Mono and Flux in the

who calls subscribe on Flux or Mono in reactive webapplication

ε祈祈猫儿з 提交于 2020-06-22 03:19:07
问题 I am looking at some examples of reactive web applications and i am seeing them like this @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public Mono<Person> findById(...) { return exampleService.findById(...); } @RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseBody public Flux<Person> findAll() { Flux<Person> persons = exampleService.findAll(); return persons; } When i am reading about the Mono and Flux in the

How to log request body in spring Webflux Java

不想你离开。 提交于 2020-06-17 09:32:07
问题 I am receiving some XML payload in a POST request and want to see the payload as received for debugging purposes. Below (my custom WebFilter) code logs the URI and request headers as expected but not the request body/payload, must be something wrong with my reactive code - final ServerHttpRequest request = exchange.getRequest(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); LOGGER.info("Request: uri={}", request.getURI()); LOGGER.info("Request: headers={}", request.getHeaders()

Spring WebFlux - how to get data from DB to use in the next step

馋奶兔 提交于 2020-06-16 07:11:27
问题 I use Spring WebFlux (Project Reactor) and I'm facing the following problem: I have to get some data from db to use them to call another service - everything in one stream. How to do that? public Mono<MyObj> saveObj(Mono<MyObj> obj) { return obj .flatMap( ob-> Mono.zip( repo1.save( ...), repo2 .saveAll(...) .collectList(), repo3 .saveAll(...) .collectList()) .map(this::createSpecificObject)) .doOnNext(item-> createObjAndCallAnotherService(item)); } private void createObjAndCallAnotherService