project-reactor

The method publishOn of Flux doesn't not work as expected

做~自己de王妃 提交于 2019-12-25 09:41:46
问题 I'm trying to integrate a blocking consumer as a Flux subscriber in Reactor Aluminium-SR1. I would like to use a parallel Scheduler , to execute the blocking operations concurrently. I've implement a main class to describe my intention: package etienne.peiniau; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.publisher.Flux; import reactor.core.scheduler.Schedulers; import reactor.util.function.Tuple2; public class Main { public static void

Netty HttpServer api changed/differs from available examples

♀尐吖头ヾ 提交于 2019-12-25 08:04:27
问题 Netty server instantiation in Arjen Poutsma's blog post and Josh Long's video example is done by creating an reactor.ipc.netty.http.HttpServer instance and then calling it's start or startAndAwait method with an ReactorHttpHandlerAdapter instance as an argument. However the API seems to have changed as now start and startAndAwait methods now expect a lambda with the following signature: java.util.function.Function<? super reactor.ipc.netty.http.HttpChannel,? extends org.reactivestreams

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

Spring Reactor: How to throw an exception when publisher emit a value?

我的未来我决定 提交于 2019-12-25 01:27:28
问题 I'm learning reactive programming with Reactor and I want to implement registration scenario where a user can have many accounts assigned to the same profile. However the username assigned to the profile and the phone assigned to the account must be unique. As you can see in the following snippet, this scenario will be easy to implement if Reactor was offering the operator switchIfNotEmpty . public Mono<PersonalAccountResponse> createPersonalAccount(PersonalAccountRequest request) { return

Why is the handler for a REST endpoint being accessed twice, when accessed from a WebClient?

人走茶凉 提交于 2019-12-24 20:22:40
问题 This is a second attempt, with revised demo code that, hopefully, better illustrates the issue. The code has been stripped down to remove all elements except those demonstrating the issue being encountered. Add Note: Some additional testing was done, and the results posted as an answer (vice extending this post). It may be that this is "expected behavior", but I'm still trying to understand "the why". The code "works", in that it returns the expected information (either a String, or a list of

How to await when all http requests are finished using spring webClient?

拥有回忆 提交于 2019-12-24 19:14:01
问题 I want to execute http request for each queue element. These requests shoule be called in parallel. Also I need to await the termination of all requests. I developed the following code: List<Mono<MyResponseDTO>> monoList = queue.stream() .map(jobStatusBunch -> webClient .post() .uri("localhost:8080/api/some/url") .bodyValue(convertToRequestDto(someBean)) .retrieve() .toEntity(String.class) .filter(HttpEntity::hasBody) .map(stringResponseEntity -> { try { return objectMapper.readValue

How to build a reactive pipeline with different Publishers without losing data?

浪尽此生 提交于 2019-12-24 06:46:27
问题 Imagine you have code like this: public List<Group> addUserToGroups(String username, String label) { Mono<User> userMono = webClient.getUser(username); User user = userMono.block(); Flux<Group> groupsFlux = webClient.getGroups(label); List<Group> groups = groupsFlux.collectList().block(); groups.forEach(group -> webClient.addUserToGroup(user.getId(), group.getId()).block() ); return groups; } But now you want to refactor this code into a non-blocking reactive pipeline, and the main method to

How can one slow down emissions form Flux.interval?

巧了我就是萌 提交于 2019-12-23 20:08:34
问题 Would this need back pressure or is there a simpler way? For example in the below code , I want the spin function to be called every 2 seconds. Sometimes 'spin' can take longer time to compute than 2 second interval, in which case I do not want any interval emissions to queue up. But in the below code they do queue up. In the code below, the first 4 spin function calls take 10 seconds and the rest take 1 second. As a result the Flux.interval emissions 'catch up' once the function gets faster.

Downlolad and save file from ClientRequest using ExchangeFunction in Project Reactor

给你一囗甜甜゛ 提交于 2019-12-23 19:36:50
问题 I have problem with correctly saving a file after its download is complete in Project Reactor. class HttpImageClientDownloader implements ImageClientDownloader { private final ExchangeFunction exchangeFunction; HttpImageClientDownloader() { this.exchangeFunction = ExchangeFunctions.create(new ReactorClientHttpConnector()); } @Override public Mono<File> downloadImage(String url, Path destination) { ClientRequest clientRequest = ClientRequest.create(HttpMethod.GET, URI.create(url)).build();

Project Reactor and the Java memory model

拟墨画扇 提交于 2019-12-23 17:23:58
问题 I am trying to understand what guarantees with respect to data visibility Project reactor provides to application code. For e.g. I would expect the below code to fail but it does not after a million iterations. I am changing the state of a typical POJO on thread A and reading it back from thread B. Does Reactor guarantee POJO changes are visible across thread? public class Main { public static void main(String[] args) { Integer result = Flux.range(1, 1_000_000) .map(i -> { Data data = new