Instacart Kaushik Gopal Jun 21, 2017

RxJava 1 -> RxJava 2 (Understanding the Changes)

Article Summary

RxJava 2 was a complete rewrite with breaking APIs. If you're still on version 1, here's what changed and why it matters.

Kaushik Gopal breaks down the RxJava 1 to 2 migration in this technical guide. The rewrite wasn't arbitrary: RxJava 2 now implements the Reactive Streams specification, making interop between reactive libraries much easier.

Key Takeaways

Critical Insight

RxJava 2's adoption of Reactive Streams standardization means better library interop, but requires understanding the Flowable vs Observable distinction.

Part 2 covers the subscription disposal changes that trip up most teams during migration.

About This Article

Problem

RxJava 1 and RxJava 2 handle backpressure differently, which creates real problems when you try to use both in the same project. Developers end up having to explicitly qualify Observable imports with package names (rx.Observable vs io.reactivex.Observable) just to keep them straight.

Solution

Kaushik Gopal suggests migrating all your code at once instead of doing it gradually. This avoids the messy period where you have to remember which version behaves which way.

Impact

RxJava 2 follows the Reactive Streams specification, which means it works well with other reactive libraries that implement the same 4-interface spec. Publisher, Subscriber, Subscription, and Processor are the interfaces involved.