project-reactor

Splitting a WebClient Post of a Streaming Flux into JSON Arrays

馋奶兔 提交于 2019-12-11 06:49:08
问题 I am using a third-party REST controller which accepts an array of JSON objects and returns a single object response. When I POST from a WebClient using a limited Flux the code works (I assume, because the Flux completes). However, when the Flux is potentially unlimited, how do I; POST in chunks of arrays? Capture the response, per POSTed array? Stop the transmission of the Flux ? Here is my bean; public class Car implements Serializable { Long id; public Car() {} public Car(Long id) { this

Adapting RxJava 1.1.5 to Reactor Core 3.1.0.M3

给你一囗甜甜゛ 提交于 2019-12-11 06:39:19
问题 I am trying to use a library that uses RxJava 1.1.5 with Spring WebFlux (i.e. Reactor Core 3.1.0.M3) but I am having trouble adapting Observable to Flux . I thought this would be relatively straightforward, but my adapter isn't working: import reactor.core.publisher.Flux; import rx.Observable; import rx.Subscriber; import rx.Subscription; public static <T> Flux<T> toFlux(Observable<T> observable) { return Flux.create(emitter -> { final Subscription subscription = observable.subscribe(new

Spring Boot v2.0.0.M2 webflux and actuator

那年仲夏 提交于 2019-12-11 06:35:41
问题 I'm not able to get Actuator work with Spring Boot v2.0.0.M2 and Netty . The following dependencies are used in the build.gradle : compile "org.springframework.boot:spring-boot-starter-actuator" compile "org.springframework.boot:spring-boot-starter-data-redis-reactive" compile "org.springframework.boot:spring-boot-starter-webflux" compile "org.springframework.boot:spring-boot-configuration-processor" runtime "org.springframework.boot:spring-boot-devtools" I don't see information related to

Using project reactor mergeWith() operator in order to achieve “if/elseif/else” branching logic

删除回忆录丶 提交于 2019-12-11 06:05:01
问题 I am trying to use project reactor mergeWith operator in order to achieve a if/elseif/else branching logic as described here: RxJS, where is the If-Else Operator. The provided samples are written in RxJS but the underlying idea remains the same. Basically the idea is to use the filter operator on 3 monos/publishers (therefore with 3 different predicates) and merge the 3 monos as follows (here they are RxJS Observables of course): const somethings$ = source$ .filter(isSomething) .do(something)

Returning Mono<UpdateResult> with Reactive MongoDB template

断了今生、忘了曾经 提交于 2019-12-11 05:12:16
问题 I am trying to get an UpdateResult in a reactive way using MongoDB reactive template in Spring Boot. The problem is that the update part won't execute as I am not subscribing to it, but I don't really know how to do the 2 operations and returning one value with the reactive paradigm. This is what I am trying: @GetMapping("\update") public Mono<UpdateResult> updateTask(@RequestParam(name="taskId") { Mono<UpdateResult> updateResult = mongoReactiveTemplate .findById(taskId, Task.class) .flatmap

Reactor Flux replay(int history) method not working as expected

Deadly 提交于 2019-12-11 05:11:30
问题 I'm trying to make an example of a Flux with Project Reactor that has the following characteristics: A single hot observable, which emits one item per second. Two subscribers, each of them using a separate thread of the publisher. A limited history when calling replay() , so some items will be missed in case one of the subscribers is too slow. Then I coded this sample: import java.time.Duration; import reactor.core.publisher.ConnectableFlux; import reactor.core.publisher.Flux; import reactor

Fire and forget with reactor

别说谁变了你拦得住时间么 提交于 2019-12-11 04:25:14
问题 I have a method like below in my Spring boot app. public Flux<Data> search(SearchRequest request) { Flux<Data> result = searchService.search(request);//this returns Flux<Data> Mono<List<Data>> listOfData = result.collectList(); // doThisAsync() // here I want to pass this list and run some processing on it // the processing should happen async and the search method should return immediately. return result; } //this method uses the complete List<Data> returned by above method public void

How can I perform flatMap using multiple threads in Reactor?

*爱你&永不变心* 提交于 2019-12-11 01:53:32
问题 I have tried running a flatMap on a Flux range followed by subscribeOn and it seems all operations run on the same thread. Is this normal? Flux.range(0, 1000000).log().flatMap{ it + 1 }.subscribeOn(Schedulers.parallel()).subscribe() 回答1: You can create a ParallelFlux as follows: Flux.range(0, 100000).parallel(2).runOn(Schedulers.parallel()).log().map{ it + 1 }.subscribe() ^^^^^^^^^^^ ^^^^^^use runOn ^^^^^^^^^^^ 来源: https://stackoverflow.com/questions/53409567/how-can-i-perform-flatmap-using

How to verify with StepVerifier that provided Mono did not completed?

北战南征 提交于 2019-12-11 00:58:00
问题 With StepVerifier it is very easy to check whether provided Mono has completed (just by expectComplete() method in StepVerifier ), but what should I do if need to check the opposite case ? I tried to use this approach: @Test public void neverMonoTest() { Mono<String> neverMono = Mono.never(); StepVerifier.create(neverMono) .expectSubscription() .expectNoEvent(Duration.ofSeconds(1)) .thenCancel() .verify(); } and such test passes. But this is false positive, because when I replace Mono.never()

Reactive Kafka : Exactly Once Processing with Transaction

孤者浪人 提交于 2019-12-11 00:34:58
问题 Initially triggered via api call 1. Service A produces m1 to topic1 (non transactional send) 2. Service B consumes topic1 and does some processing (begin tx) 3. Service B produces m2 to topic2 (commit tx) 4. Service A consumes topic2 (begin tx) Here is my producer config: final Map<String, Object> props = Maps.newConcurrentMap(); props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers); props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class); props.put