project-reactor

Will Reactor provide remoting?

99封情书 提交于 2019-12-19 08:16:11
问题 I'm trying to find out whether we should use Akka or Reactor for our next project. One of the most important questions is if the future framework of choice will provide remoting. As i saw, Akka offers this just in the way we'd like to have it. In the GitHub wiki, unfortunately the TCP-server/client sections are blank and i couldn't find other informations about that yet. Will reactor provide remoting? 回答1: I don't think Akka and Reactor are Apples to Apples. Reactor is purposely minimal, with

How to collect paginated API responses using spring boot WebClient?

核能气质少年 提交于 2019-12-18 16:55:31
问题 I have a paginated response from an URL, I want to keep on hitting the next page URL which I get from the previous response and keep on collecting items till I don't have a "nextPage" URL in my response. How to achieve this in a reactive way using spring boot WebClient from WebFlux with out blocking? Request1: GET /items response: { items: [...] nextPage: "/items?page=2" } Request2: GET /items?page=2 response: { items: [...] nextPage: "/items?page=3" } Request3: GET /items?page=3 response: {

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

Spring 5 Web Reactive - How can we use WebClient to retrieve streamed data in a Flux?

[亡魂溺海] 提交于 2019-12-18 08:58:14
问题 The current milestone (M4) documentation shows and example about how to retrieve a Mono using WebClient : WebClient webClient = WebClient.create(new ReactorClientHttpConnector()); ClientRequest<Void> request = ClientRequest.GET("http://example.com/accounts/{id}", 1L) .accept(MediaType.APPLICATION_JSON).build(); Mono<Account> account = this.webClient .exchange(request) .then(response -> response.body(toMono(Account.class))); How can we get streamed data (from a service that returns text/event

how to retry Spring WebClient to retry the operation based on the response?

房东的猫 提交于 2019-12-14 04:22:00
问题 I've been learning spring webflux and got stuck into this one. I've made a request to REST API from Spring app using WebClient. I want to retry the request based on the response. lets say if the response has property status: 'not-ready' , then I need to retry the same operation after a second. I tried the following way, but not sure how to implement it public Flux<Data> makeHttpRequest(int page) { Flux<Data> data = webClient.get() .uri("/api/users?page=" + page) .retrieve() .bodyToFlux(Data

Reactor way to cancel Subscriptions

蹲街弑〆低调 提交于 2019-12-14 03:43:47
问题 I try to figure out Reactor Project and I'm looking for a way to cancel Subscriptions. I know that after making Subscription of for example Flux I can get reference to Cancellation object which can be used to send onCancel Signal, but this is only after making subscription and I need to hold that reference in some kind of Collection. Is there better way to get Cancellation object? Or just to cancel Subscriptions. Maybe some kind of place which contains reference to all active Subscriptions -

How do I limit the events currently being processed in a flatMap process?

折月煮酒 提交于 2019-12-14 03:06:04
问题 Given the following piece of code public static void main(String[] args) { long start = System.currentTimeMillis(); Flux.<Long>generate(s -> s.next(System.currentTimeMillis() - start)) .flatMap(DemoApp::delayedAction) .doOnNext(l -> System.out.println(l + " -- " + (System.currentTimeMillis() - start))) .blockLast(Duration.ofSeconds(3)); } private static Publisher<? extends Long> delayedAction(Long l) { return Mono.just(l).delayElement(Duration.ofSeconds(1)); } One can see from the output that

How to mock Mono.create

隐身守侯 提交于 2019-12-13 03:58:21
问题 I'm using the spock framework and need to return a mocked Mono from a Mono.create(..) I've tried: GroovyMock(Mono) as well as GroovyMock(Mono, global:true) 1 * Mono.create(_ as MonoSink) >> Mono.just(returnedValue) But I get the message that there were too few assertions for the above code. Here is the actual Mono.create code Mono.create{ sink -> myAPISoap.getStuffAsync( username, password, info, { outputFuture -> try { sink.success(outputFuture.get()) } catch(Exception e){ sink.error(e) } }

Cannot use 'subscribe' or 'subscribeWith' with 'ReactorNettyWebSocketClient' in Kotlin

穿精又带淫゛_ 提交于 2019-12-13 03:35:14
问题 The Kotlin code below successfully connects to a Spring WebFlux server, sends a message and prints each message sent via the stream that is returned. fun main(args: Array<String>) { val uri = URI("ws://localhost:8080/myservice") val client = ReactorNettyWebSocketClient() val input = Flux.just(readMsg()) client.execute(uri) { session -> session.send(input.map(session::textMessage)) .thenMany( session.receive() .map(WebSocketMessage::getPayloadAsText) .doOnNext(::println) // want to replace

Reactive parallelization doesn't work

北战南征 提交于 2019-12-12 10:23:22
问题 Using project Reactor 3.0.4.RELEASE. Conceptually, should be same in RxJava as well. public Mono<Map<String, Boolean>> refreshPods(List<String> apps) { return pods(apps) .filter(this::isRunningAndNotThisApp) .groupBy(Item::getName) .flatMap(g -> g .distinct(Item::getIp) .collectList() // TODO: This doesn't seem to be working as expected .subscribeOn(Schedulers.newParallel("par-grp")) .flatMap(client::refreshPods)) .flatMap(m -> Flux.fromIterable(m.entrySet())) .collectMap(Map.Entry::getKey,