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.

Reactive Streams and the Wide World of Groovy

670 views

Published on

The concept of Reactive Streams (aka Reactive Extensions, Reactive Functional Programming, or simply Rx) has become increasingly popular recently, and with good reason. The Reactive Streams specification provides a universal abstraction for asynchronously processing data received across multiple sources (e.g. database, user input, third-party services), and includes mechanisms for controlling the rate at which data is received. This makes it a powerful tool within a Microservice platform. And did we mention that the Groovy lang community is quite involved?

In this talk we’ll explore the various features and concepts of Reactive Streams. We’ll talk about some typical use cases for Rx and more importantly, how to implement them. We’ll focus primarily on RxGroovy and Ratpack, then provide example implementations that show you how to get started with this powerful technique.

Published in: Software
  • My personal experience with research paper writing services was highly positive. I sent a request to ⇒ www.HelpWriting.net ⇐ and found a writer within a few minutes. Because I had to move house and I literally didn’t have any time to sit on a computer for many hours every evening. Thankfully, the writer I chose followed my instructions to the letter. I know we can all write essays ourselves. For those in the same situation I was in, I recommend ⇒ www.HelpWriting.net ⇐.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Writing a good research paper isn't easy and it's the fruit of hard work. For help you can check writing expert. Check out, please ⇒ www.HelpWriting.net ⇐ I think they are the best
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Reactive Streams and the Wide World of Groovy

  1. 1. Reactive Streams and the Wide World of Groovy Steve Pember CTO, ThirdChannel Gr8Conf US, 2016 THIRDCHANNEL @svpember
  2. 2. “Reactive Streams”, “Reactive Extensions”, or “Rx”
  3. 3. THIRDCHANNEL @svpember Agenda • The Problem • What are Reactive Streams? • … Did someone say ‘Groovy’? • Rx in depth • Demo Time!
  4. 4. THIRDCHANNEL @svpember The Problem: The Need to go Reactive
  5. 5. Really, it’s Two problems
  6. 6. THIRDCHANNEL @svpember 1) Performance Demands Are Always Increasing
  7. 7. We Use Technology from the Beginning of Web Development
  8. 8. Things Slow Down
  9. 9. Users get angry quickly
  10. 10. –Johnny Appleseed “Type a quote here.”
  11. 11. Let’s Keep Our Users Happy And Engaged
  12. 12. THIRDCHANNEL @svpember 2) The Rise of Microservices
  13. 13. Multiple Integration Points
  14. 14. It’s Not Only Users That Use Up Resources
  15. 15. So what to do?
  16. 16. Free up resources with Async Operations & Non-Blocking I/O
  17. 17. Async is Hard for Humans
  18. 18. THIRDCHANNEL @svpember Agenda • The Problem • What are Reactive Streams?
  19. 19. Collections + Time
  20. 20. Single abstraction over data from many sources
  21. 21. THIRDCHANNEL @svpember
  22. 22. Observer Pattern Push (not Pull) based Iterators
  23. 23. Stream-Based Functional Programming
  24. 24. Imperative vs Reactive Stream
  25. 25. Groovy Collections supports stream-like options
  26. 26. If this makes sense to you, then you’re ready for Rx
  27. 27. Streams with Extensions for Reactive Programming
  28. 28. Rx makes Async behavior easy!
  29. 29. (Reactive Pull) Backpressure
  30. 30. 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
  31. 31. Rx Simplifies Complex Work
  32. 32. …Once you understand, of course…
  33. 33. THIRDCHANNEL @svpember Agenda • The Problem • What are Reactive Streams? • … Did someone say ‘Groovy’?
  34. 34. THIRDCHANNEL @svpember
  35. 35. THIRDCHANNEL @svpember We should probably mention RxJava
  36. 36. Brings Reactive Streams to the JVM
  37. 37. But Quickly Switch to rxGroovy
  38. 38. THIRDCHANNEL @svpember
  39. 39. THIRDCHANNEL @svpember
  40. 40. THIRDCHANNEL @svpember • High performance web framework • Non-opinionated • Non-Blocking Network Stack • Built on Reactive Streams, Netty, Java 8, Guice • Fully embodies reactive • Deterministic Asynchronous code Take a Look at Ratpack
  41. 41. Includes rxRatpack module, but we’ll talk about that later
  42. 42. THIRDCHANNEL @svpember Agenda • The Problem • What are Reactive Streams? • … Did someone say ‘Groovy’? • Rx in depth
  43. 43. … our as much as we can get through
  44. 44. The following is rxJava 1.x rxJava 2.x will release by EOY
  45. 45. THIRDCHANNEL @svpember Key Terms:
  46. 46. An Observable is like Promise ++
  47. 47. An Observable pushes items to Subscribers
  48. 48. Subscribers receive and operate on emitted data
  49. 49. Observables and Subscribers operate on a Scheduler
  50. 50. THIRDCHANNEL @svpember More Details…
  51. 51. THIRDCHANNEL @svpember
  52. 52. THIRDCHANNEL @svpember
  53. 53. Thankfully, there are shortcuts
  54. 54. THIRDCHANNEL @svpember
  55. 55. THIRDCHANNEL @svpember
  56. 56. Streams are Composable
  57. 57. THIRDCHANNEL @svpember
  58. 58. THIRDCHANNEL @svpember You can get much power from 5 functions • filter • map • reduce • groupBy • flatMap
  59. 59. THIRDCHANNEL @svpember
  60. 60. THIRDCHANNEL @svpember
  61. 61. THIRDCHANNEL @svpember
  62. 62. THIRDCHANNEL @svpember
  63. 63. First Mental Leap: An Observable of Observables
  64. 64. –Johnny Appleseed “Type a quote here.”
  65. 65. THIRDCHANNEL @svpember
  66. 66. THIRDCHANNEL @svpember
  67. 67. THIRDCHANNEL @svpember Hot vs Cold
  68. 68. Cold Observable: finite data, on demand Hot Observable: infinite data, as it’s ready
  69. 69. THIRDCHANNEL @svpember Asynchronous Streams
  70. 70. THIRDCHANNEL @svpember
  71. 71. THIRDCHANNEL @svpember
  72. 72. THIRDCHANNEL @svpember
  73. 73. THIRDCHANNEL @svpember BackPressure
  74. 74. THIRDCHANNEL @svpember
  75. 75. THIRDCHANNEL @svpember Can only Mitigate Hot Streams • throttle • sample • window • buffer • drop
  76. 76. THIRDCHANNEL @svpember Stream Interaction
  77. 77. Don’t Unsubscribe from Observables Programmatically complete them when another Observable fires
  78. 78. 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
  79. 79. Well done.
  80. 80. The keyPress stream is reacting to itself
  81. 81. THIRDCHANNEL @svpember
  82. 82. THIRDCHANNEL @svpember Demo Time
  83. 83. THIRDCHANNEL @svpember Any Questions?
  84. 84. Thank You! @svpember spember@gmail.com THIRDCHANNEL @svpember
  85. 85. 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

×