Search code examples
rx-javarx-java2

PublishSubject with backpressure in RxJava 2.x


I am currently choosing between RxJava 1.x or 2.x for my current project.

I basically need a PublishSubject with a backpressure strategy onBackpressureLatest().

I want to choose RxJava 2.x, but i can't quite get my head around on how to apply a backpressure strategy to a PublishSubject, as it inherits from Observable and not from Flowable.


Could you please tell me how to create a PublishSubject with a onBackpressureLatest() backpressure strategy in RxJava 2.x ?


Solution

  • In 2.x the backpressure was moved to the base type Flowable and its hot partners PublishProcessor, ReplayProcessor etc.

    PublishProcessor<Integer> pp = PublishProcessor.create();
    Flowable<Integer> out = pp.onBackpressureLatest();