spring-webflux

Spring webflux data in ReactJs UI

孤人 提交于 2019-12-11 07:31:56
问题 I am playing around with spring webflux. I have created a project which would listen on a mongo capped collection and return the flux of data as and when it comes. I am using @Tailable in my repository method. My controller looks like this @GetMapping("/findall") public Flux<Product>> findAll() { return productRepository.findAllProducts().; } This is working perfectly fine. I tested this by addind a doOnNext(...) , Whenever there is a new item added to my capped collection, consumer inside

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

Request is blocked in end 2 end testing in a webflux application

风格不统一 提交于 2019-12-11 06:59:00
问题 Another problem I encountered in end 2 end tests, setting invalid credentials will cause the sent request blocked till it is timeout. Source codes: https://github.com/hantsy/spring-reactive-sample/blob/master/security-method/src/test/java/com/example/demo/IntegrationTests.java#L83-L94 @Test public void savingPostsWhenInvalidCredentialsThenUnauthorized() throws Exception { this.rest .post() .uri("/posts") .attributes(invalidCredentials()) .body(BodyInserters.fromObject(Post.builder().title(

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

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

How to test exception with @WebfluxTest

蹲街弑〆低调 提交于 2019-12-11 05:01:31
问题 I am trying to test exception path for my controller with @WebfluxTest , but it is always throws a server exception and then return a 500 error. The test codes is here: @Test @Ignore // ignore it temporarily public void getPostByNonExistedId_shouldReturn404() { given(posts.findById("1")) .willReturn(Mono.empty()); client.get().uri("/posts/1").exchange() .expectStatus().isNotFound(); verify(this.posts, times(1)).findById(anyString()); verifyNoMoreInteractions(this.posts); } The controller

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

Spring WebFlux reactive WebSocket prevent connection closing

别说谁变了你拦得住时间么 提交于 2019-12-11 04:10:04
问题 I'm working on simple chat module for my application using Spring WebFlux with ReactiveMongoRepository on backend and Angular 4 on front. I'm able to receive data through WebSocketSession but after streaming all messages from db i want to keep the connection so i could update message list. Can anyone give me clues how to achieve that, or maybe i'm following wrong assumptions ? Java Backend responsible for WebSocket, my subscriber only logs current state, nothing relevant there:

Spring WebFlux Webclient receiving an application/octet-stream file as a Mono

浪尽此生 提交于 2019-12-11 02:29:34
问题 I'm prototyping a small Spring WebFlux application in Kotlin. This application needs to GET a tar archive from a remote REST endpoint and store it locally on disk. Sounds simple. I first created an integration test that starts the spring server and one other WebFlux server with a mock REST endpoint that serves the tar archive. The test should go like: 1) app: GET mock-server/archive 2) mock-server: response with status 200 and tar archive in body as type attachment 3) app: block until all

In spring boot webflux based microservice, who is the subscriber?

点点圈 提交于 2019-12-11 01:41:05
问题 Note: Here the terms Subscriber and Subscription are being used from the reactive streams specification. Consider the following @RestController methods in a spring boot webflux based microservice. @GetMapping(path = "/users", produces = MediaType.APPLICATION_JSON_VALUE) public Flux<TradingUser> listUsers() { return this.tradingUserRepository.findAll(); } @GetMapping(path = "/users/{username}", produces = MediaType.APPLICATION_JSON_VALUE) public Mono<TradingUser> showUsers(@PathVariable String