project-reactor

WebFlux functional: How to detect an empty Flux and return 404?

情到浓时终转凉″ 提交于 2019-12-12 07:58:25
问题 I'm having the following simplified handler function (Spring WebFlux and the functional API using Kotlin). However, I need a hint how to detect an empty Flux and then use noContent() for 404, when the Flux is empty. fun findByLastname(request: ServerRequest): Mono<ServerResponse> { val lastnameOpt = request.queryParam("lastname") val customerFlux = if (lastnameOpt.isPresent) { service.findByLastname(lastnameOpt.get()) } else { service.findAll() } // How can I detect an empty Flux and then

Is this bug in Flux.cache(history, ttl)?

吃可爱长大的小学妹 提交于 2019-12-12 03:58:41
问题 The following code StepVerifier.withVirtualTime((Supplier<Publisher<?>>) () -> Flux.just(1, 2, 3).cache(2, Duration.ofSeconds(10))) .thenAwait(Duration.ofSeconds(5)) .expectNext(2, 3) .verifyComplete(); fails with exception java.lang.AssertionError: expectation "expectNext(2)" failed (expected value: 2; actual value: 1) If I change the expected values to .expectNext(1, 2, 3) it will pass. So it does not respect the history provided in cache method? 回答1: Caching and TTL are a bit more tricky

how to get the object returned from joinPoint.proceed() with Spring AOP and WebFlux

泪湿孤枕 提交于 2019-12-12 01:16:50
问题 I have a simple aspect (see below) with @Around annotation. This aspect works when the the application don't use reactive paradigm. But when the application returns Mono or Flux doesn't works properly. I need to get the object returned from the method to generate a JSON object to use as log, generate events, etc. Here is my code that works in a non reactive classes: @Around("@annotation(simpleEvent)") public Object logExecutionTime(ProceedingJoinPoint joinPoint, SimpleEvent simpleEvent)

WebFlux not sending data when using application/stream+json

非 Y 不嫁゛ 提交于 2019-12-11 21:22:30
问题 I have a reactive core WebClient to post to a given endpoint. The payload is a flux of Job objects and the content-type is application/stream+json Flux jobFlux = Flux.just(new Job()); Mono<JsonNode> response = localEP.post().uri( "/dev/job" ) .contentType(MediaType.APPLICATION_STREAM_JSON) .body( BodyInserters.fromObject(jobFlux)) .retrieve() .bodyToMono( JsonNode.class ); On the server end I have tried both a Spring Controller style and Spring Web Reactive FunctionHandler to process the

Dynamically merging Fluxes

允我心安 提交于 2019-12-11 17:55:55
问题 I've written an application with the server side applying the Event Sourcing pattern, with all incoming commands processed sequentially with the Reactor. I get those commands from client connexions. Alas, my Netty Pipeline publishes commands with no respect for the Reactive Contract. Reactor Netty could be a part of a solution, because it enforces the Reactive Contract down to the Netty Pipeline. But with Reactor Netty, each connection in a Flux. Connections are added and removed. How do I

When FlatMap will listen to multiple sources concurrently?

限于喜欢 提交于 2019-12-11 16:42:48
问题 What are the situations which cause Flux::flatMap to listen to multiple sources (0...infinity) concurrently? I found out, while experimenting, that when the upstream send signals to flatMap in thread thread-upstream-1 and there are N inner streams which flatMap will listen to and each of them send signals in different thread: thread-inner-stream-i for 1<=i<=N , than for every 1<=i<=N if thread-upstream-1 != thread-inner-stream-i , flatMap will listen concurrently to all the inner streams. I

How to use Micrometer timer together with webflux endpoints

限于喜欢 提交于 2019-12-11 15:49:09
问题 IS there any simple way to use Micrometer timers with Webflux controllers? It seems that @Timed works only with non-reactive methods. For reactive it records very low time values. I found a similar question: How to use Micrometer Timer to record duration of async method (returns Mono or Flux) but the answers were too complex for such a common issue Any ideas? 回答1: If you want to measure time for Web-flux methods/calls you can then use easily metrics directly from Flux/Mono (plus configure

Issue with use of project reactor's flatMap and switchIfEmpty operators

最后都变了- 提交于 2019-12-11 07:37:18
问题 I have an issue with a reactive chain relying on flatMap() and switchIfEmpty() . For some reason, one of the Mono does not emit anything... This is the public handler method calling the others: //Throws: NoSuchElementException: Source was empty public Mono<ServerResponse> createUser(ServerRequest serverRequest) { Hooks.onOperatorDebug(); Mono<User> userMono = serverRequest.bodyToMono(User.class); return validateUser(userMono) .switchIfEmpty(saveUser(userMono)) .single(); } This is the first

Spring integration xml file errors out on reactor StringUtils

和自甴很熟 提交于 2019-12-11 07:27:15
问题 I have a spring integration sftp flow which I load as a child context within my overall application context. This is based on the dynamic ftp SI example. My integration flow has nothing about reactor or streams in it. Its a simple flow with one direct channel connected with a sftp-outbound-gateway to transfer files to a sftp server. I can even run units tests and the flow work fine (is able to transfer files) but when I run an integration test which loads the full parent application and then

Spring reactive : mixing RestTemplate & WebClient

孤街醉人 提交于 2019-12-11 07:19:25
问题 I have two endpoints : /parent and /child/{parentId} I need to return list of all Child public class Parent { private long id; private Child child; } public class Child { private long childId; private String someAttribute; } However, call to /child/{parentId} is quite slow, so Im trying to do this: Call /parent to get 100 parent data, using asynchronous RestTemplate For each parent data, call /child/{parentId} to get detail Add the result call to /child/{parentId} into resultList When 100