I have my code in Rxjava and I want to change it reactor project. My rxjava code is
public Observable<Map<Integer, Data>> getObject(List<Integer> ids, List<String> filters) {
if (ids == null || ids.isEmpty()) {
return Observable.just(new HashMap<>());
}
return Observable.fromCallable(() -> {
Map<Integer, Data> data= client.getObject(ids, filters).getData();
return data;
});
}
How do I write this code using Flux / Mono? What should I use(Flux / Mono)?
Basically I want to know how to store Map to Flux like Observable or should I use Mono
Observable to Flux Conversion can be achieved using
Flux<User> convFlux = Flux.from(observable.toFlowable(BackpressureStrategy.BUFFER));
Different BackpressureStrategy that can be applied are as below:
package io.reactivex;
public enum BackpressureStrategy {
MISSING,
ERROR,
BUFFER,
DROP,
LATEST;
private BackpressureStrategy() {
}
}
Conversion between RxJava 2 types and Mono/Flux back and forth and compose backpressure, cancellation and fusion where applicable please refer https://projectreactor.io/docs/adapter/release/api/reactor/adapter/rxjava/RxJava2Adapter.html
You may refer to https://github.com/reactor/lite-rx-api-hands-on/blob/complete/src/main/java/io/pivotal/literx/Part09Adapt.java which has all the conversion implemented as an exercise, thanks to Simon Baslé.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With