reactive-streams

how save document to MongoDb with com.mongodb.reactivestreams.client

两盒软妹~` 提交于 2021-01-01 06:45:01
问题 I am trying to insert a document in MongoDb throw reactive driver: com.mongodb.reactivestreams.client According to official guide "... Only when a Publisher is subscribed to and data requested will the operation happen... Once the document has been inserted the onNext method will be called " and provided an example which I tried bellow without success. By debugging I see that onSubscribe is called but onNext bellow is never called and I checked in MongoDb the document isn't inserted also.

how save document to MongoDb with com.mongodb.reactivestreams.client

喜欢而已 提交于 2021-01-01 06:44:14
问题 I am trying to insert a document in MongoDb throw reactive driver: com.mongodb.reactivestreams.client According to official guide "... Only when a Publisher is subscribed to and data requested will the operation happen... Once the document has been inserted the onNext method will be called " and provided an example which I tried bellow without success. By debugging I see that onSubscribe is called but onNext bellow is never called and I checked in MongoDb the document isn't inserted also.

How to emit cumulative sum only from a reactive stream?

孤街浪徒 提交于 2020-08-10 19:57:27
问题 I've a use case where the stream should only emit when the cumulative "sum" equals or exceeds a given value, n. Let's take the example of six integers with n = 5. +---+------+---------+ | i | Emit | Sum | +---+------+---------+ | 1 | - | 1 | | 2 | - | 3 | | 3 | 5 | 1 | | 4 | 5 | 0 | | 5 | 5 | 0 | | 2 | 2 | 0 (end) | +---+------+---------+ As you can see, nothing is emitted unless the sum equals or exceeds 5, except for the last element, which is emitted anyway. Once an item is emitted, the

publishOn vs subscribeOn in Project Reactor 3

久未见 提交于 2020-05-25 08:00:31
问题 I am using publishOn vs subscribeOn both on the same flux as follows: System.out.println("*********Calling Concurrency************"); List<Integer> elements = new ArrayList<>(); Flux.just(1, 2, 3, 4) .map(i -> i * 2) .log() .publishOn(Schedulers.elastic()) .subscribeOn(Schedulers.parallel()) .subscribe(elements::add); System.out.println("-------------------------------------"); Although, when i use both, nothing is printed in logs. But when i use only publishOn, i got the following info logs:

How REST endpoints are auto subscribed while calling from Browser/REST Client?

限于喜欢 提交于 2020-05-23 09:21:40
问题 In ProjectReactor or Reactive Streams, Nothing Happens Until You subscribe(). Reactive streams data flow will not happen unless until someone subscribe to it, but I see for all REST APIs like finds, save and inserts are not calling subscribe explicitly but data is flowing between producer and subscribers. @RestController class PersonController { private final PersonRepository repository; public PersonController(PersonRepository repository) { this.repository = repository; } @GetMapping("/all")

What is the difference between Schedulers.newElastic and Schedulers.elastic methods?

允我心安 提交于 2020-04-13 06:15:43
问题 I am working on Flux and Mono and using them in multi threaded environment and using the Schedular which provide the worker thread. There are many options to start the Schedular using elastic, parallel and newElastic. Here is the code which i used: System.out.println("------ elastic --------- "); Flux.range(1, 10) .map(i -> i / 2) .publishOn(Schedulers.elastic()).log() .blockLast(); System.out.println("------ new elastic --------- "); Flux.range(1, 10) .map(i -> i / 2).log() .publishOn

How to handle errors in Spring reactor Mono or Flux?

点点圈 提交于 2020-01-15 09:36:28
问题 I have below code retuning Mono<Foo>: try { return userRepository.findById(id) // step 1 .flatMap(user -> barRepository.findByUserId( user.getId()) // step 2 .map(bar-> Foo.builder().msg("Already exists").build()) // step 3 .switchIfEmpty(barRepository.save(Bar.builder().userId(user.getId()).build()) // step 4 .map(bar-> Foo.builder().msg("Created").build()) // step 5 )) .doOnError(throwable -> Mono.just(handleError(throwable))); } catch(Exception e) { log.error("from catch block"); return

How to deal with two Fluxes in Spring Reactive Programing?

徘徊边缘 提交于 2019-12-25 01:48:36
问题 I have two Fluxes Flux<Foo> foo; Flux<Bar> bar; class Foo String id String prop1 String barId class Bar String barId String color boolean isInFoo foo and bar both have barId property. The size of foo is always equal to or less than size of bar but usually it is much less than bar size (number of Bars in Flux. For example Foo could represent a few selected items out of a basket of Bar items although the two are different objects. Bar has a boolean flag isInFoo with default value = false, which

How to use Reactive Streams for NIO binary processing?

拈花ヽ惹草 提交于 2019-12-20 12:36:35
问题 Are there some code examples of using org.reactivestreams libraries to process large data streams using Java NIO (for high performance)? I'm aiming at distributed processing, so examples using Akka would be best, but I can figure that out. It still seems to be the case that most (I hope not all) examples of reading files in scala resort to Source (non-binary) or direct Java NIO (and even things like Files.readAllBytes !) Perhaps there is an activator template I've missed? (Akka Streams with

How to correctly read Flux<DataBuffer> and convert it to a single inputStream

断了今生、忘了曾经 提交于 2019-12-18 12:18:36
问题 I'm using WebClient and custom BodyExtractor class for my spring-boot application WebClient webLCient = WebClient.create(); webClient.get() .uri(url, params) .accept(MediaType.APPLICATION.XML) .exchange() .flatMap(response -> { return response.body(new BodyExtractor()); }) BodyExtractor.java @Override public Mono<T> extract(ClientHttpResponse response, BodyExtractor.Context context) { Flux<DataBuffer> body = response.getBody(); body.map(dataBuffer -> { try { JaxBContext jc = JaxBContext