Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Gr8conf US 2015: Reactive Options for Groovy

1,097 views

Published on

Reactive applications and Reactive programming are an alternative to the standard thread-based imperative programming model that can result in flexible, concise code. The Reactive approach has gained popularity recently for one simple reason: we need alternative designs and architectures to meet today’s demands. However, it can be difficult to shift one’s mind to think in Reactive terms. It doesn’t help that the descriptions around the web can be contradictory and the library documentation can be obscure.

In this talk, we’ll explore the concepts of Reactive and Reactive Programming. We’ll demonstrate some of the useful Reactive functions and examine some practical implementations - including how we’re currently using Reactive libraries in production code. Most importantly, we’ll look at some of the open source options available to us in the Groovy community, including Reactor, RxJava, and the Java 8 stream API. If Reactive is new to you, this should be an excellent introduction.

Published in: Software
  • Be the first to comment

Gr8conf US 2015: Reactive Options for Groovy

  1. 1. THIRDCHANNEL @svpember Reactive Options for Groovy Steve Pember CTO, ThirdChannel @svpember
  2. 2. What is ‘Reactive’?
  3. 3. THIRDCHANNEL @svpember Possible Reactive Definitions • Reactive Programming
  4. 4. Imperative: A = B+C at that moment in time Reactive: A = B+C whenever B or C change values
  5. 5. THIRDCHANNEL @svpember Possible Reactive Definitions • Reactive Programming • Reactive Systems
  6. 6. THIRDCHANNEL @svpember Possible Reactive Definitions • Reactive Programming • Reactive Systems • Reactive Streams / Reactive Extensions (Rx)
  7. 7. THIRDCHANNEL @svpember Possible Reactive Definitions • Reactive Programming • Reactive Systems • Reactive Streams / Reactive Extensions (Rx)
  8. 8. THIRDCHANNEL @svpember Agenda • Reactive Systems • Reactive Streams / Reactive Extensions • Reactive Groovy
  9. 9. The Need For Reactive (The Reactive Manifesto)
  10. 10. –Johnny Appleseed “Type a quote here.”
  11. 11. –Johnny Appleseed “Type a quote here.” http://www.internetlivestats.com/internet-users/
  12. 12. THIRDCHANNEL @svpember
  13. 13. –Johnny Appleseed “Type a quote here.”
  14. 14. –Johnny Appleseed “Type a quote here.” https://medium.com/reactive-programming/what-is-reactive-programming-bc9fa7f4a7fc
  15. 15. Need to Handle As Many Users As Possible
  16. 16. THIRDCHANNEL @svpember Reactive Systems • The Need for Reactive • 4 Reactive Principles
  17. 17. THIRDCHANNEL @svpember
  18. 18. THIRDCHANNEL @svpember Reactive Systems • The Need for Reactive • 4 Reactive Principles • Responsive
  19. 19. THIRDCHANNEL @svpember
  20. 20. THIRDCHANNEL @svpember Reactive Systems • The Need for Reactive • 4 Reactive Principles • Responsive • Resilient
  21. 21. –Johnny Appleseed “Type a quote here.”
  22. 22. Embrace Failure
  23. 23. Independent Things Fail Independently
  24. 24. THIRDCHANNEL @svpember Reactive Systems • The Need for Reactive • 4 Reactive Principles • Responsive • Resilient • Elastic (Scalable)
  25. 25. THIRDCHANNEL @svpember Reactive Systems • The Need for Reactive • 4 Reactive Principles • Responsive • Resilient • Elastic (Scalable) • Asynchronous / Message-Driven
  26. 26. Humans Are Terrible At Concurrency
  27. 27. Recommended: Actors
  28. 28. THIRDCHANNEL @svpember Akka
  29. 29. –Johnny Appleseed “Type a quote here.”
  30. 30. –Johnny Appleseed “Type a quote here.”
  31. 31. Never Block Your Resources
  32. 32. THIRDCHANNEL @svpember Agenda • Reactive Systems • Reactive Streams / Reactive Extensions
  33. 33. “A standard for asynchronous stream processing of potentially infinite data, across boundaries, with non-blocking backpressure”
  34. 34. THIRDCHANNEL @svpember
  35. 35. THIRDCHANNEL @svpember Story Time
  36. 36. THIRDCHANNEL @svpember Story Time
  37. 37. THIRDCHANNEL @svpember Story Time
  38. 38. THIRDCHANNEL @svpember Story Time 2012 - MS Open Source’s RX! (wut?)
  39. 39. THIRDCHANNEL @svpember Story Time 2012 - MS Open Source’s RX! (wut?)
  40. 40. –Johnny Appleseed “Type a quote here.”
  41. 41. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push
  42. 42. THIRDCHANNEL @svpember
  43. 43. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber
  44. 44. An Observable is a push-based collection
  45. 45. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber • Hot / Cold
  46. 46. THIRDCHANNEL @svpember
  47. 47. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber • Hot / Cold • Composable
  48. 48. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber • Hot / Cold • Composable • Async is Easy!
  49. 49. The Subscriber & Observable can be independently Async
  50. 50. THIRDCHANNEL @svpember
  51. 51. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber • Hot / Cold • Composable • Async is Easy! • Backpressure
  52. 52. THIRDCHANNEL @svpember
  53. 53. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber • Hot / Cold • Composable • Async is Easy! • Backpressure • Observable Interaction
  54. 54. THIRDCHANNEL @svpember Rx: More Than a Stream • Pull vs Push • Observable / Subscriber • Hot / Cold • Composable • Async is Easy! • Backpressure • Observable Interaction • You really only need 4 functions
  55. 55. THIRDCHANNEL @svpember 4 functions! • filter • map / flatMap • groupBy • reduce
  56. 56. THIRDCHANNEL @svpember Agenda • Reactive Systems • Reactive Streams / Reactive Extensions • Groovy Options
  57. 57. THIRDCHANNEL @svpember A Few Groovy Options… • Akka
  58. 58. THIRDCHANNEL @svpember A Few Groovy Options… • Akka • Akka Streams
  59. 59. THIRDCHANNEL @svpember Akka & Akka Streams • Library • Definition of Reactive System • Typesafe • Actor-Based Concurrency • Implemented Streams on Top of Actor Model
  60. 60. THIRDCHANNEL @svpember A Few Groovy Options… • Akka • Akka Streams • RxJava / RxGroovy
  61. 61. THIRDCHANNEL @svpember RxJava • Library • Comes out of Netflix • Part of reactivex.io • Reactive Streams on the JVM
  62. 62. THIRDCHANNEL @svpember
  63. 63. THIRDCHANNEL @svpember A Few Groovy Options… • Akka • Akka Streams • RxJava / RxGroovy • Ratpack
  64. 64. THIRDCHANNEL @svpember • HTTP application server • Non-opinionated • Built on Reactive Streams, Netty, Java 8, Guava • Fully embodies reactive
  65. 65. THIRDCHANNEL @svpember A Few Groovy Options… • Akka • Akka Streams • RxJava / RxGroovy • Ratpack • Reactor
  66. 66. THIRDCHANNEL @svpember • Library • Reactive Streams • Reactor Pattern • Built on LMAX Ring Buffer / Disrupter
  67. 67. THIRDCHANNEL @svpember
  68. 68. VS
  69. 69. THIRDCHANNEL @svpember
  70. 70. THIRDCHANNEL @svpember
  71. 71. THIRDCHANNEL @svpember
  72. 72. THIRDCHANNEL @svpember • Groovy Parallelism and Concurrency • Built into the language! • Actors • DataFlow • Async Closures
  73. 73. Do I Have Time for a Demo?
  74. 74. Final Thought: What About Java 8 Streams?
  75. 75. 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
  76. 76. Thank You! Questions? @svpember
  77. 77. 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/ • 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

×