io.github.resilience4j.adapter.RxJava2Adapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of resilience4j-rxjava2 Show documentation
Show all versions of resilience4j-rxjava2 Show documentation
Resilience4j is a lightweight, easy-to-use fault tolerance library designed for Java8 and functional programming
package io.github.resilience4j.adapter;
import io.github.resilience4j.core.EventPublisher;
import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.processors.FlowableProcessor;
import io.reactivex.processors.PublishProcessor;
import io.reactivex.subjects.PublishSubject;
import io.reactivex.subjects.Subject;
public class RxJava2Adapter {
/**
* Converts the EventPublisher into a Flowable.
*
* @param eventPublisher the event publisher
* @param the type of the event
* @return the Flowable
*/
public static Flowable toFlowable(EventPublisher eventPublisher) {
PublishProcessor publishProcessor = PublishProcessor.create();
FlowableProcessor flowableProcessor = publishProcessor.toSerialized();
eventPublisher.onEvent(flowableProcessor::onNext);
return flowableProcessor;
}
/**
* Converts the EventPublisher into an Observable.
*
* @param eventPublisher the event publisher
* @param the type of the event
* @return the Observable
*/
public static Observable toObservable(EventPublisher eventPublisher) {
PublishSubject publishSubject = PublishSubject.create();
Subject serializedSubject = publishSubject.toSerialized();
eventPublisher.onEvent(serializedSubject::onNext);
return serializedSubject;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy