reactive options for groovy programming

110
THIRDCHANNEL @svpember Reactive Options for Groovy Steve Pember CTO, ThirdChannel @svpember SpringOne 2GX, 2015

Upload: spring-by-pivotal

Post on 21-Jan-2018

785 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Reactive Options for Groovy

Steve PemberCTO, ThirdChannel

@svpemberSpringOne 2GX, 2015

Page 2: Reactive Options for Groovy Programming

What is ‘Reactive’?

Page 3: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

Page 4: Reactive Options for Groovy Programming

Imperative: A = B+C at that moment in time

Reactive: A = B+C whenever B or C change values

Page 5: Reactive Options for Groovy Programming
Page 6: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 7: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

• Reactive Systems

Page 8: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

• Reactive Systems

• Reactive Streams / Reactive Extensions (Rx)

Page 9: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

• Reactive Systems

• Reactive Streams / Reactive Extensions (Rx)

Page 10: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Agenda• Reactive Systems

• Reactive Streams / Reactive Extensions

• Reactive Groovy

Page 11: Reactive Options for Groovy Programming

The Need For Reactive(The Reactive Manifesto)

Page 12: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 13: Reactive Options for Groovy Programming
Page 14: Reactive Options for Groovy Programming
Page 15: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

http://www.internetlivestats.com/internet-users/

Page 16: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 17: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 18: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

https://medium.com/reactive-programming/what-is-reactive-programming-bc9fa7f4a7fc

Page 19: Reactive Options for Groovy Programming

Need to Handle As Many Users As Possible

Page 20: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

Page 21: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 22: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

Page 23: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 24: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

• Resilient

Page 25: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 26: Reactive Options for Groovy Programming

Embrace Failure

Page 27: Reactive Options for Groovy Programming
Page 28: Reactive Options for Groovy Programming

Independent Things Fail Independently

Page 29: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

• Resilient

• Elastic (Scalable)

Page 30: Reactive Options for Groovy Programming
Page 31: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

• Resilient

• Elastic (Scalable)

• Asynchronous / Message-Driven

Page 32: Reactive Options for Groovy Programming
Page 33: Reactive Options for Groovy Programming

Humans Are Terrible At Concurrency

Page 34: Reactive Options for Groovy Programming

The Manifesto is not Concrete

Page 35: Reactive Options for Groovy Programming

Recommended: Actors

Page 36: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Akka

Page 37: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 38: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 39: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 40: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 41: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 42: Reactive Options for Groovy Programming

Anyway.

Page 43: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 44: Reactive Options for Groovy Programming

Hooray for Microservices

Page 45: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Agenda• Reactive Systems

• Reactive Streams / Reactive Extensions

Page 46: Reactive Options for Groovy Programming

–Me (now)

“A standard for asynchronous stream processing of potentially infinite data, across boundaries,

with non-blocking backpressure”

Page 47: Reactive Options for Groovy Programming

VS

Page 48: Reactive Options for Groovy Programming

–Jafar Husain https://www.youtube.com/watch?v=XRYN2xt11Ek

“Collection + time”

Page 49: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 50: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 51: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Story Time

Page 52: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Story Time

Page 53: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Story Time

Page 54: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Story Time

2012 - MS Open Source’s RX! (wut?)

Page 55: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Story Time

2012 - MS Open Source’s RX! (wut?)

Page 56: Reactive Options for Groovy Programming
Page 57: Reactive Options for Groovy Programming

–Johnny Appleseed

“Type a quote here.”

Page 58: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

Page 59: Reactive Options for Groovy Programming
Page 60: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

Page 61: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 62: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

Page 63: Reactive Options for Groovy Programming

An Observable is a push-based collection

Page 64: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

Page 65: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 66: Reactive Options for Groovy Programming
Page 67: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

Page 68: Reactive Options for Groovy Programming
Page 69: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

• Async is Easy!

Page 70: Reactive Options for Groovy Programming

The Subscriber & Observable can be independently Async

Page 71: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 72: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

• Async is Easy!

• Backpressure

Page 73: Reactive Options for Groovy Programming
Page 74: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 75: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

• Async is Easy!

• Backpressure

• Observable Interaction

Page 76: Reactive Options for Groovy Programming

Don’t Unsubscribe from Events / Observables.

Programatically complete them when some other event or Observable fires.

Page 77: Reactive Options for Groovy Programming
Page 78: Reactive Options for Groovy Programming
Page 79: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Agenda• Reactive Systems

• Reactive Streams / Reactive Extensions

• Groovy Options

Page 80: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

Page 81: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

Page 82: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Akka & Akka Streams• Library

• Definition of Reactive System

• Typesafe

• Actor-Based Concurrency

• Implemented Streams on Top of Actor Model

Page 83: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

• RxJava / RxGroovy

Page 84: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

RxJava• Library

• Comes out of Netflix

• Part of reactivex.io

• Reactive Streams on the JVM

Page 85: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 86: Reactive Options for Groovy Programming
Page 87: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

• RxJava / RxGroovy

• Ratpack

Page 88: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

• HTTP application server

• Non-opinionated

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

• Fully embodies reactive

Page 89: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 90: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 91: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

• RxJava / RxGroovy

• Ratpack

• Reactor

Page 92: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

• Library

• Reactive Streams

• Reactor Pattern

• Built on LMAX Ring Buffer / Disrupter

Page 93: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 94: Reactive Options for Groovy Programming

VS

Page 95: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 96: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 97: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Page 98: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

• Groovy Parallelism and Concurrency

• Built into the language!

• Actors

• DataFlow

• Async Closures

Page 99: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Getting Started

Page 100: Reactive Options for Groovy Programming

Demo Time

Page 101: Reactive Options for Groovy Programming

That’s Great, But How do I get started?

Page 102: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Advice for exploring RX• Start thinking in terms of streams / pipelines

• Drop in one of the libraries into your project

• Observe a finite data set (Observe.from())

• You only need 4 functions

• Be Aware of Subscribe / Observe On

• Create your own Observables

• Connect your Observables

Page 103: Reactive Options for Groovy Programming

Final Thought: What About Java 8 Streams?

Page 104: Reactive Options for Groovy Programming

THIRDCHANNEL @svpember

Java 8 Streams• Built into the language

• Meant for ‘pull’ on finite Iterables

• Parallelization has rather severe problems (e.g. https://dzone.com/articles/think-twice-using-java-8)

• No Async

• vs Observables -> potentially infinite items, async, with back pressure

Page 105: Reactive Options for Groovy Programming

Actual Final Thought: Embrace Reactive!

Page 106: Reactive Options for Groovy Programming
Page 107: Reactive Options for Groovy Programming

Thank You!@svpember

Page 108: Reactive Options for Groovy Programming

Questions?

Page 109: Reactive Options for Groovy Programming

Image Credits• 1000ms Time To glass: https://docs.google.com/presentation/d/1IRHyU7_crIiCjl0Gvue0WY3eY_eYvFQvSfwQouW9368/present?

slide=id.g1e697bbb_0_7• internet users in the world: http://www.internetlivestats.com/internet-users/• internet users vs Facebook: https://medium.com/reactive-programming/what-is-reactive-programming-bc9fa7f4a7fc• reactivex logo: https://www.stickermule.com/marketplace/2223-rx-reactive-extensions-logo-4• cheetah: www.livescience.com/21944-usain-bolt-vs-cheetah-animal-olympics.html• dominoes: https://www.flickr.com/photos/louish/5611657857/sizes/l/in/photostream/• 300 / Spartans: http://www.300themovie.com/• latop punch: http://walls4joy.com/wallpaper/730566-angry-laptops-punch• mailman: http://thebrandtstandard.com/2013/02/09/u-s-post-office-to-end-saturday-letter-delivery-this-summer/• Actors diagram: https://blog.codecentric.de/en/2015/08/introduction-to-akka-actors/• actor system: http://letitcrash.com/post/30585282971/discovering-message-flows-in-actor-systems-with• slow down: http://forthefamily.org/reminder-slow/• Buffalo: http://news.sd.gov/newsitem.aspx?id=15164• Midvale School for the Gifted: http://www.2ndfirstlook.com/2012/09/gary-larson.html• Blueprints: https://en.wikipedia.org/wiki/File:House_Plans_(Blueprints).pdf

Page 110: Reactive Options for Groovy Programming

More On Reactive:• 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