Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducción a RxJava

Introducción a RxJava

Brief introduction to reactive development on Java

Gilbert Guevara

December 14, 2016
Tweet

Other Decks in Programming

Transcript

  1. Agenda:
 1. What is RxJava? 2. Why Consider Rx? 3.

    When is Rx appropriate? 4. Key types 5. Sequence basics
  2. What is RxJava? RxJava, the Netflix implementation of the original

    Microsoft library. Rx is a powerful tool that enables the solution of problems in an elegant declarative style, familiar to functional programmers. • Reactive programming is a specification for dealing with asynchronous streams of data. •Reactive provides tools for transforming and combining streams and for managing flow-control. •Marble diagrams provide an interactive canvas for visualizing reactive constructs. •Resembles Java Streams API but the resemblance is purely superficial. •Attach to hot streams to attenuate and process asynchronous data feeds.
  3. What is RxJava? RxJava, the Netflix implementation of the original

    Microsoft library. Rx is a powerful tool that enables the solution of problems in an elegant declarative style, familiar to functional programmers. • Reactive programming is a specification for dealing with asynchronous streams of data. •Reactive provides tools for transforming and combining streams and for managing flow-control. •Marble diagrams provide an interactive canvas for visualizing reactive constructs. •Resembles Java Streams API but the resemblance is purely superficial. •Attach to hot streams to attenuate and process asynchronous data feeds.
  4. Why Consider Rx? At its core, RxJava simplifies development because

    it raises the level of abstraction around threading. That is, as a developer you don’t have to worry too much about the details of how to perform operations that should occur on different threads. This is particularly attractive since threading is challenging to get right and, if not correctly implemented, can cause some of the most difficult bugs to debug and fix. • Unitive. •Extensible. •Declarative. •Composable. •Transformative.
  5. Should use Rx: •UI events like mouse move, button click.

    •Domain events like property changed, collection updated, "Order Filled", "Registration accepted" etc. •Infrastructure events like from file watcher, system and WMI events. •Integration events like a broadcast from a message bus or a push event from WebSockets API or other low latency middleware like Nirvana. •Integration with a CEP engine like StreamInsight or StreamBase. •API consumption, external services integration.
  6. Could use Rx:
 • Result of Future or equivalent pattern.


    Won’t use:
 • Translating iterables to observables, just for the sake of working on them through an Rx library.
  7. Creating a sequence. Simple factory methods • Observable.just • Observable.empty

    • Observable.never • Observable.error • Observable.defer • Observable.create Functional unfolds • Observable.range • Observable.interval • Observable.timer Observable.from
  8. Transforming a sequence. • Map • Cast and ofType •

    Timestamp and timeInterval • Materialize and dematerialize • FlatMap • ConcatMap • FlatMapIterable