Skip to content

Instantly share code, notes, and snippets.

@dferrandizmont
Last active January 8, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dferrandizmont/d3a3809562c7c115d49c45134e725ebd to your computer and use it in GitHub Desktop.
Save dferrandizmont/d3a3809562c7c115d49c45134e725ebd to your computer and use it in GitHub Desktop.
[PART 1.0 - Getting started] Why Rx #rxjava #rxjavaguide

PART 1 - Getting started

Why Rx

Users expect real time data. They want their tweets now. Their order confirmed now. They need prices accurate as of now. Their online games need to be responsive. As a developer, you demand fire-and-forget messaging. You don't want to be blocked waiting for a result. You want to have the result pushed to you when it is ready. Even better, when working with result sets, you want to receive individual results as they are ready. You do not want to wait for the entire set to be processed before you see the first row. The world has moved to push; users are waiting for us to catch up. Developers have tools to push data, this is easy. Developers need tools to react to push data

Welcome to Rx. This book is based on Rx.NET's www.introtorx.com and it introduces beginners to 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. Rx has several benefits:

  • Unitive
    • Queries in Rx are done in the same style as other libraries inspired by functional programming, such as Java streams. In Rx, one can use functional style transformations on event streams.
  • Extensible
    • RxJava can be extended with custom operators. Although Java does not allow for this to happen in an elegant way, RxJava offers all the extensibility one can find Rx implementations in other languages.
  • Declarative
    • Functional transformations are read in a declarative way.
  • Composable
    • Rx operators can be combined to produce more complicated operations.
  • Transformative
    • Rx operators can transform one type of data to another, reducing, mapping or expanding streams as needed.

When is Rx appropriate?

Rx is fit for composing and consuming sequences of events. We present some of the use cases for Rx, according to www.introtorx.com

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.

Could use Rx

  • Result of Future or equivalent pattern

Those patterns are already well adopted and you may find that introducing Rx on top of that does not add to the development process.

Won't use Rx

  • Translating iterables to observables, just for the sake of working on them through an Rx library.
Continue reading
Previous Next
Key types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment