Introduce
RxJava is a Java VM implementation of Reactive Extensions: a library for composing asynchronous and event-based programs by using observable sequences.
It extends the observer pattern to support sequences of data/events and adds operators that allow you to compose sequences together declaratively while abstracting away concerns about things like low-level threading, synchronization, thread-safety and concurrent data structures.
Version 3.x
- single dependency: Reactive-Streams
- Java 8+ (Android desugar friendly)
- Java 8 lambda-friendly API
- fixed API mistakes and many limits of RxJava 2
- intended to be a replacement for RxJava 2 with relatively few binary incompatible changes
- non-opinionated about the source of concurrency (threads, pools, event loops, fibers, actors, etc.)
- async or synchronous execution
- virtual time and schedulers for parameterized concurrency
- test and diagnostic support via test schedulers, test consumers and plugin hooks
Getting started
Setting up the dependency
The first step is to include RxJava 3 into your project, Example for Maven:
<dependency> <groupId>io.reactivex.rxjava3</groupId> <artifactId>rxjava</artifactId> <version>3.x.y</version> </dependency>
and for Ivy:
<dependency org="io.reactivex.rxjava3" name="rxjava" rev="3.x.y" />
and for SBT:
libraryDependencies += "io.reactivex" %% "rxscala" % "0.26.5" libraryDependencies += "io.reactivex.rxjava3" % "rxjava" % "3.x.y"
and for Gradle:
compile 'io.reactivex.rxjava3:rxjava:3.x.y'
(Please replace x
and y
with the latest version numbers
Hello World
The second is to write the Hello World program:
package rxjava.examples; import io.reactivex.rxjava3.core.*; public class HelloWorld { public static void main(String[] args) { Flowable.just("Hello world").subscribe(System.out::println); } }
Note that RxJava 3 components now live under io.reactivex.rxjava3
and the base classes and interfaces
live under io.reactivex.rxjava3.core
.
Learn more about RxJava in general on the Wiki Home .