reactive-programming

How apply pagination in reactive Spring Data?

旧时模样 提交于 2019-11-30 03:16:34
问题 In Spring Data, we have PagingAndSortingRepository which inherits from CrudRepository . In reactive Spring Data, we only have ReactiveSortingRepository which inherits from ReactiveCrudRepository . How could we make pagination in a reactive way ? Will we able to make this in future with ReactivePagingAndSortingRepository for instance? 回答1: Reactive Spring Data MongoDB repositories do not provide paging in the sense of paging how it's designed for imperative repositories. Imperative paging

Chain two retrofit observables w/ RxJava

被刻印的时光 ゝ 提交于 2019-11-30 01:36:14
I want to execute 2 network calls one after another. Both network calls return Observable. Second call uses data from successful result of the first call, method in successful result of second call uses data from both successful result of the first and of the second call. Also i should be able to handle both onError "events" differently. How can i achieve this avoiding callback hell like in example below: API().auth(email, password) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<AuthResponse>() { @Override public void call(final

How to get data from observable in angular2

£可爱£侵袭症+ 提交于 2019-11-30 01:12:07
I am trying to print the result of http call in Angular using rxjs Consider the following code import { Component, Injectable, OnInit } from '@angular/core'; import { Http, HTTP_PROVIDERS } from '@angular/http'; import 'rxjs/Rx'; @Injectable() class myHTTPService { constructor(private http: Http) {} configEndPoint: string = '/my_url/get_config'; getConfig() { return this.http .get(this.configEndPoint) .map(res => res.json()); } } @Component({ selector: 'my-app', templateUrl: './myTemplate', providers: [HTTP_PROVIDERS, myHTTPService], }) export class AppComponent implements OnInit { constructor

How to customize SpringWebFlux WebClient JSON deserialization?

给你一囗甜甜゛ 提交于 2019-11-30 01:07:26
问题 I'm using a spring-webflux WebClient (build 20170502.221452-172) to access a Web application producing a stream of Entry objects (application/stream+json) like this: final WebClient producerClient = WebClient.create("http://localhost:8080/"); Flux<Entry> entries = producerClient.get().uri("json-stream") .accept(MediaType.APPLICATION_STREAM_JSON) .exchange() .flatMapMany(clientResponse -> clientResponse.bodyToFlux(Entry.class)); While the deserialization of the Entry objects works fine for

Mono vs Flux in Reactive Stream

六眼飞鱼酱① 提交于 2019-11-30 00:42:40
As per the documentation: Flux is a stream which can emit 0..N elements: Flux<String> fl = Flux.just("a", "b", "c"); Mono is a stream of 0..1 elements: Mono<String> mn = Mono.just("hello"); And as both are the implementations of the Publisher interface in the reactive stream. Can't we use only Flux in most of the cases as it also can emit 0..1, thus satisfying the conditions of a Mono? Or there are some specific conditions when only Mono needs to be used and Flux can not handle the operations? Please suggest. In many cases, you are doing some computation or calling a service and you expect

Read continous bytestream from Stream using TcpClient and Reactive Extensions

孤者浪人 提交于 2019-11-29 23:59:24
问题 Consider the following code: internal class Program { private static void Main(string[] args) { var client = new TcpClient(); client.ConnectAsync("localhost", 7105).Wait(); var stream = client.GetStream(); var observable = stream.ReadDataObservable().Repeat(); var s = from d in observable.Buffer(4) let headerLength = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(d.ToArray(), 2)) let b = observable.Take(headerLength) select b.ToEnumerable().ToArray(); s.Subscribe(a => Console.WriteLine("{0

RxJava - fetch every item on the list

两盒软妹~` 提交于 2019-11-29 22:10:47
I have a method that returns an Observable<ArrayList<Long>> , which are ids of some Items. I'd like to go through this list and download every Item using another method that returns Observable<Item> . How would I do this using RxJava operators? Miguel Lavigne Here's a small self contained example public class Example { public static class Item { int id; } public static void main(String[] args) { getIds() .flatMapIterable(ids -> ids) // Converts your list of ids into an Observable which emits every item in the list .flatMap(Example::getItemObservable) // Calls the method which returns a new

What is LINQ to events a.k.a RX Framework?

此生再无相见时 提交于 2019-11-29 20:49:03
What is LINQ to events a.k.a RX Framework aka the Reactive Extensions in .NET 4.0 (but also available as backported versions)? In other words, what is all the stuff in System.Reactive.dll for? .NET Rx team (this is not an official name) found that any push sequence (events, callbacks) can be viewed as a pull sequence (as we normally do while accessing enumerables) as well – or they are Dual in nature. In short observer/observable pattern is the dual of enumeration pattern. So what is cool about about this duality? Anything you do with Pull sequences (read declarative style coding) is

RxJava Observing on calling/subscribing thread

吃可爱长大的小学妹 提交于 2019-11-29 20:09:28
I have some trouble understandig how subscribeOn/observeOn works in RxJava. I've created simple app with observable that emits solar system planet names, does some mapping and filtering and prints results. As I understand, scheduling work to background thread is done via subscribeOn operator (and it seems to work fine). Observing on background thread also works fine with observeOn operator. But I have trouble in understanding, how to observe on calling thread (either if it is main thread or any other). It is easily done on Android with AndroidSchedulers.mainThread() operator, but I don't know

EventBus/PubSub vs (reactive extensions) RX with respect to code clarity in a single threaded application

此生再无相见时 提交于 2019-11-29 19:52:13
Currently, I am using an EventBus/ PubSub architecture/pattern with Scala (and JavaFX) to implement a simple note organizing app (sort of like an Evernote client with some added mind mapping functionality) and I have to say that I really like EventBus over the observer pattern. Here are some EventBus libraries : https://code.google.com/p/guava-libraries/wiki/EventBusExplained http://eventbus.org (currently seems to be down) this is the one I am using in my implementation. http://greenrobot.github.io/EventBus/ Here is a comparison of EventBus libraries : http://codeblock.engio.net/37/ EventBus