RxJava is an open-source Java implementation of the reactive programming paradigm, an API for asynchronous programming with observable streams. Based on Reactive Extensions on .NET, RxJava provides an event-based programming model, via observables, observers, subjects, and actions.
This course takes a detailed look at how to create reactive systems using RxJava. We explore the API in detail, and explain how to use RxJava to create responsive, resilient, elastic, and message-driven solutions using recognised best practices and contemporary design patterns.
This module begins with an explanation of the Reactive Manifesto, which describes the aims and benefits of reactive systems. We then show how to start creating reactive systems using RxJava. We introduce the Observable class and show how to create observable data from some simple data sources. We then describe the concept of subscriptions and show how to create some simple subscribers.
Functional programming (FP) is an essential ingredient in reactive systems. This module explains what FP is, and explores common techniques including pure functions, higher-order functions, recursion, and currying. During our discussions, we'll explain the issues surrounding closures in Java and see how lambda techniques can address these issues.
Observables lie at the heart of RxJava. This module describes how to create Observables from various types of data source, including arrays/collections, scalar objects, ranges, timers, and intervals. We then describe various subscriber techniques, including creating custom observers and implementing custom call-back semantics.
This module explores some of the features and capabilities in the Observable class, which allow you to filter items, be selective about the items emitted, and implement life-cycle hooks to perform custom processing when data items are emitted, when an error occurs, and/or when the Observable has completed emitting data items.
The module also describes how to map items to different values (including the use of flap maps), and then shows how to accumulate items into a single result. These are very common tasks when processing data.
RxJava allows you to combine Observables together. This allows you to implement sophisticated policies on where you get data from, and how you multiplex data from several concurrent data streams. We explore all the possible combination options in this module.
The module also shows how to implement boolean dependencies between your Observables, e.g. to provide a default value if a source is empty or to favour items from the first Observable that emits. There are some interesting techniques you need to learn about here.
The module concludes with a discussion on error handling. We show how to swallow errors, switch Observable data source on error, and retry on errors.
RxJava is single-threaded by default, but you can schedule work on different threads if you want to. This is highly desirable in most situations. This module describes how the scheduling model works in RxJava and explores the various strategies for allocating work to scheduled workers.
The module also describe the predefined schedulers, i.e. the immediate scheduler, the trampoline scheduler, the newThread scheduler, the computation scheduler, and the io scheduler.
It's not difficult to get into a situation where an Observable is emitting more rapidly than a subscriber can consume. How do you handle this situation?
There are several strategies for exercising flow control and back-pressure in RxJava. The aim is to alleviate the problems caused when a quickly-producing Observable meets a slow-consuming observer. We explore these strategies in this module, including the use of throttling, sampling, debouncing, buffers, and windows.