reactive streams and the wide world of groovy

90
Reactive Streams and the Wide World of Groovy Steve Pember CTO, ThirdChannel THIRDCHANNEL @svpember

Upload: steve-pember

Post on 14-Apr-2017

461 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Reactive Streams and the Wide World of Groovy

Reactive Streams and the Wide World of Groovy

Steve Pember CTO, ThirdChannel

THIRDCHANNEL @svpember

Page 2: Reactive Streams and the Wide World of Groovy

“Reactive Streams”, “Reactive Extensions”, or “Rx”

Page 3: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Agenda• The Problem

• What are Reactive Streams?

• … Did someone say ‘Groovy’?

• Rx in depth

• Demo Time!

Page 4: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

The Problem: The Need to go Reactive

Page 5: Reactive Streams and the Wide World of Groovy

Really, it’s Two problems

Page 6: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

1) Performance Demands Are Always Increasing

Page 7: Reactive Streams and the Wide World of Groovy
Page 8: Reactive Streams and the Wide World of Groovy

We Use Technology from the Beginning of Web Development

Page 9: Reactive Streams and the Wide World of Groovy
Page 10: Reactive Streams and the Wide World of Groovy

Things Slow Down

Page 11: Reactive Streams and the Wide World of Groovy

Users get angry quickly

Page 12: Reactive Streams and the Wide World of Groovy

–Johnny Appleseed

“Type a quote here.”

Page 13: Reactive Streams and the Wide World of Groovy

Let’s Keep Our Users Happy And Engaged

Page 14: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

2) The Rise of Microservices

Page 15: Reactive Streams and the Wide World of Groovy

Multiple Integration Points

Page 16: Reactive Streams and the Wide World of Groovy

It’s Not Only Users That Use Up Resources

Page 17: Reactive Streams and the Wide World of Groovy

So what to do?

Page 18: Reactive Streams and the Wide World of Groovy

Free up resources with Async Operations & Non-Blocking I/O

Page 19: Reactive Streams and the Wide World of Groovy

Async is Hard for Humans

Page 20: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Agenda• The Problem

• What are Reactive Streams?

Page 21: Reactive Streams and the Wide World of Groovy

Collections + Time

Page 22: Reactive Streams and the Wide World of Groovy
Page 23: Reactive Streams and the Wide World of Groovy

Single abstraction over data from many sources

Page 24: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 25: Reactive Streams and the Wide World of Groovy

Observer Pattern Push (not Pull) based Iterators

Page 26: Reactive Streams and the Wide World of Groovy

Stream-Based Functional Programming

Page 27: Reactive Streams and the Wide World of Groovy

Imperative vs Reactive Stream

Page 28: Reactive Streams and the Wide World of Groovy

Groovy Collections supports stream-like options

Page 29: Reactive Streams and the Wide World of Groovy

If this makes sense to you, then you’re ready for Rx

Page 30: Reactive Streams and the Wide World of Groovy

Streams with Extensions for Reactive Programming

Page 31: Reactive Streams and the Wide World of Groovy

Rx makes Async behavior easy!

Page 32: Reactive Streams and the Wide World of Groovy

(Reactive Pull) Backpressure

Page 33: Reactive Streams and the Wide World of Groovy
Page 34: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

What is Rx?• Collections + Time

• A Single Abstraction over data from different sources

• Observer Pattern with Push-based iterators

• Stream Based Functional Programming

• … with Extensions for Reactive Programming

• Async is easy

• Backpressure

Page 35: Reactive Streams and the Wide World of Groovy

Rx Simplifies Complex Work

Page 36: Reactive Streams and the Wide World of Groovy

…Once you understand, of course…

Page 37: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Agenda• The Problem

• What are Reactive Streams?

• … Did someone say ‘Groovy’?

Page 38: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 39: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

We should probably mention RxJava

Page 40: Reactive Streams and the Wide World of Groovy

Brings Reactive Streams to the JVM

Page 41: Reactive Streams and the Wide World of Groovy

But Quickly Switch to rxGroovy

Page 42: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 43: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 44: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

• High performance web framework

• Non-opinionated

• Non-Blocking Network Stack

• Built on Reactive Streams, Netty, Java 8, Guice

• Fully embodies reactive

• Light-weight, self-contained deployables

Take a Look at Ratpack

Page 45: Reactive Streams and the Wide World of Groovy

http://www.infoq.com/presentations/ratpack-2015

Page 46: Reactive Streams and the Wide World of Groovy

Includes rxRatpack module, but we’ll talk about that later

Page 47: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Agenda• The Problem

• What are Reactive Streams?

• … Did someone say ‘Groovy’?

• Rx in depth

Page 48: Reactive Streams and the Wide World of Groovy

… our as much as we can get through

Page 49: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Key Terms:

Page 50: Reactive Streams and the Wide World of Groovy

An Observable is like Promise ++

Page 51: Reactive Streams and the Wide World of Groovy

An Observable pushes items to Subscribers

Page 52: Reactive Streams and the Wide World of Groovy

Subscribers receive and operate on emitted data

Page 53: Reactive Streams and the Wide World of Groovy

Observables and Subscribers operate on a Scheduler

Page 54: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

More Details…

Page 55: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 56: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 57: Reactive Streams and the Wide World of Groovy

Thankfully, there are shortcuts

Page 58: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 59: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 60: Reactive Streams and the Wide World of Groovy

Streams are Composable

Page 61: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 62: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

You can get much power from 5 functions• filter

• map

• reduce

• groupBy

• flatMap

Page 63: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 64: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 65: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 66: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 67: Reactive Streams and the Wide World of Groovy

First Mental Leap: An Observable of Observables

Page 68: Reactive Streams and the Wide World of Groovy

–Johnny Appleseed

“Type a quote here.”

Page 69: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 70: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 71: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Hot vs Cold

Page 72: Reactive Streams and the Wide World of Groovy

Cold Observable: finite data, on demand Hot Observable: infinite data, as it’s ready

Page 73: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Asynchronous Streams

Page 74: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 75: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 76: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 77: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

BackPressure

Page 78: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 79: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Can only Mitigate Hot Streams• throttle

• sample

• window

• buffer

• drop

Page 80: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Stream Interaction

Page 81: Reactive Streams and the Wide World of Groovy

Don’t Unsubscribe from Observables

Programmatically complete them when another Observable fires

Page 82: Reactive Streams and the Wide World of Groovy
Page 83: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

AutoComplete Requirements• Wait 250 ms between keypresses before querying

• If no keys are pressed, no query

• Successful queries should render movies

• Any new queries should kill in-flight queries

Page 84: Reactive Streams and the Wide World of Groovy
Page 85: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Page 86: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Demo Time: Ratpack Revisited

Page 87: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

Any Questions?

Page 88: Reactive Streams and the Wide World of Groovy

Thank You!

@svpember [email protected]

THIRDCHANNEL @svpember

Page 89: Reactive Streams and the Wide World of Groovy

THIRDCHANNEL @svpember

More Information• Reactive Groovy & Ratpack Demo: https://github.com/spember/reactive-movie-demo • Jafar Husain: RxJS: https://www.youtube.com/watch?v=XRYN2xt11Ek • Reactive Streams Spec: http://www.reactive-streams.org/ • Reactive Manifesto: http://www.reactivemanifesto.org/ • Akka: http://akka.io/ • rxJava / ReactiveX libraries: https://github.com/ReactiveX • Ratpack: http://ratpack.io/ • Reactor: https://github.com/reactor/reactor • The Introduction to Reactive Programming you’ve been missing: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754 • Martin Fowler: Stream / Pipeline programming: http://martinfowler.com/articles/refactoring-pipelines.html • Or Just on Groovy (Groovy the Awesome Parts): http://www.slideshare.net/SpringCentral/groovy-the-awesome-parts • Ratpack Web Presentation: http://www.infoq.com/presentations/ratpack-2015

Page 90: Reactive Streams and the Wide World of Groovy

Images• Empty Pool: http://www.wtok.com/home/headlines/Water-Problems-205987121.html

• Juggling: https://en.wikipedia.org/wiki/Juggling

• Directing Traffic: https://www.flickr.com/photos/tracilawson/3474012583