reactive options for groovy programming

Post on 21-Jan-2018

784 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

THIRDCHANNEL @svpember

Reactive Options for Groovy

Steve PemberCTO, ThirdChannel

@svpemberSpringOne 2GX, 2015

What is ‘Reactive’?

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

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

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

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

• Reactive Systems

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

• Reactive Systems

• Reactive Streams / Reactive Extensions (Rx)

THIRDCHANNEL @svpember

Possible Reactive Definitions• Reactive Programming

• Reactive Systems

• Reactive Streams / Reactive Extensions (Rx)

THIRDCHANNEL @svpember

Agenda• Reactive Systems

• Reactive Streams / Reactive Extensions

• Reactive Groovy

The Need For Reactive(The Reactive Manifesto)

–Johnny Appleseed

“Type a quote here.”

–Johnny Appleseed

“Type a quote here.”

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

THIRDCHANNEL @svpember

–Johnny Appleseed

“Type a quote here.”

–Johnny Appleseed

“Type a quote here.”

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

Need to Handle As Many Users As Possible

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

• Resilient

–Johnny Appleseed

“Type a quote here.”

Embrace Failure

Independent Things Fail Independently

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

• Resilient

• Elastic (Scalable)

THIRDCHANNEL @svpember

Reactive Systems• The Need for Reactive

• 4 Reactive Principles

• Responsive

• Resilient

• Elastic (Scalable)

• Asynchronous / Message-Driven

Humans Are Terrible At Concurrency

The Manifesto is not Concrete

Recommended: Actors

THIRDCHANNEL @svpember

Akka

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

–Johnny Appleseed

“Type a quote here.”

–Johnny Appleseed

“Type a quote here.”

Anyway.

THIRDCHANNEL @svpember

Hooray for Microservices

THIRDCHANNEL @svpember

Agenda• Reactive Systems

• Reactive Streams / Reactive Extensions

–Me (now)

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

with non-blocking backpressure”

VS

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

“Collection + time”

–Johnny Appleseed

“Type a quote here.”

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Story Time

THIRDCHANNEL @svpember

Story Time

THIRDCHANNEL @svpember

Story Time

THIRDCHANNEL @svpember

Story Time

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

THIRDCHANNEL @svpember

Story Time

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

–Johnny Appleseed

“Type a quote here.”

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

An Observable is a push-based collection

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

• Async is Easy!

The Subscriber & Observable can be independently Async

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

• Async is Easy!

• Backpressure

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

Rx: More Than a Stream• Collections + Time

• Pull vs Push

• Observable / Subscriber

• Hot / Cold

• Composable

• Async is Easy!

• Backpressure

• Observable Interaction

Don’t Unsubscribe from Events / Observables.

Programatically complete them when some other event or Observable fires.

THIRDCHANNEL @svpember

Agenda• Reactive Systems

• Reactive Streams / Reactive Extensions

• Groovy Options

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

THIRDCHANNEL @svpember

Akka & Akka Streams• Library

• Definition of Reactive System

• Typesafe

• Actor-Based Concurrency

• Implemented Streams on Top of Actor Model

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

• RxJava / RxGroovy

THIRDCHANNEL @svpember

RxJava• Library

• Comes out of Netflix

• Part of reactivex.io

• Reactive Streams on the JVM

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

• RxJava / RxGroovy

• Ratpack

THIRDCHANNEL @svpember

• HTTP application server

• Non-opinionated

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

• Fully embodies reactive

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

A Few Groovy Options…• Akka

• Akka Streams

• RxJava / RxGroovy

• Ratpack

• Reactor

THIRDCHANNEL @svpember

• Library

• Reactive Streams

• Reactor Pattern

• Built on LMAX Ring Buffer / Disrupter

THIRDCHANNEL @svpember

VS

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

THIRDCHANNEL @svpember

• Groovy Parallelism and Concurrency

• Built into the language!

• Actors

• DataFlow

• Async Closures

THIRDCHANNEL @svpember

Getting Started

Demo Time

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

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

Final Thought: What About Java 8 Streams?

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

Actual Final Thought: Embrace Reactive!

Thank You!@svpember

Questions?

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

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

top related