Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Reactive All the Way Down the Stack

95 vues

Publié le

Reactive applications & reactive programming result in flexible, concise, performant code and are a superior alternative to the old thread-based programming model. The reactive approach has gained popularity for a 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, particularly when one realizes that we must be Reactive up and down the entire programming stack.

In this talk we’ll explore what it means to be ‘Reactive’. We’ll examine some of the more interesting tools available to us, some of which come from the Groovy community. Specifically we’ll cover Ratpack, RxGroovy, React, and RabbitMq - along with examples and a sample implementation. We’ll demonstrate how effectively they can work together at each level of the stack - from the front end, to the back end, to handling http requests and message queue events - and how easy it can be to go Reactive all the way down.

Publié dans : Technologie
  • Soyez le premier à commenter

  • Soyez le premier à aimer ceci

Reactive All the Way Down the Stack

  1. 1. Reactive All the Way Down with Ratpack, RxGroovy, React, and RabbitMQ Steve Pember CTO, ThirdChannel Greach, 2018 @svpember
  2. 2. Reactive All the Way Down with Ratpack, RxGroovy, Groovy, rxJava, React, and RabbitMQ Steve Pember CTO, ThirdChannel Greach, 2018 @svpember
  3. 3. @svpember Agenda • Reactive ?
  4. 4. @svpember Agenda • Reactive ? • Anatomy of a Reactive Service
  5. 5. @svpember Agenda • Reactive ? • Anatomy of a Reactive Service • Technology Choices for a Reactive Service
  6. 6. @svpember Agenda • Reactive ? • Anatomy of a Reactive Service • Technology Choices for a Reactive Service • Demo
  7. 7. Advantages of Reactive
  8. 8. A Good Kind of Manifesto
  9. 9. –Johnny Appleseed “Type a quote here.”
  10. 10. @svpember Reactive Services… • Are Fast and Efficient
  11. 11. @svpember Reactive Services… • Are Fast and Efficient • Resist and are Resilient to Failure
  12. 12. @svpember Reactive Services… • Are Fast and Efficient • Resist and are Resilient to Failure • Scale Horizontally to Meet Current Demand
  13. 13. @svpember Reactive Services… • Are Fast and Efficient • Resist and are Resilient to Failure • Scale Horizontally to Meet Current Demand • Are Driven by Asynchronous Messages / Events
  14. 14. @svpember
  15. 15. @svpember
  16. 16. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput
  17. 17. You’re not Netflix. Probably
  18. 18. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput • Fast
  19. 19. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput • Fast • Reduces Synchronous Communications
  20. 20. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput • Fast • Reduces Synchronous Communications • Increased Error Protection
  21. 21. @svpember
  22. 22. @svpember
  23. 23. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput • Fast • Reduces Synchronous Communications • Increased Error Protection • “Simpler” testing
  24. 24. @svpember
  25. 25. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput • Fast • Reduces Synchronous Communications • Increased Error Protection • “Simpler” testing • Promotes a functional programming style
  26. 26. @svpember Advantages of Reactive • Highly optimized usage of resources -> optimal throughput • Fast • Reduces Synchronous Communications • Increased Error Protection • “Simpler” testing • Promotes a functional programming style • Ease of Development
  27. 27. Anatomy of a Reactive Service
  28. 28. @svpember
  29. 29. @svpember Layers • Front-End
  30. 30. Don’t Write Imperative JS
  31. 31. @svpember Layers • Front-End • HTTP
  32. 32. @svpember HTTP • C10k problem • Nonblocking I/O • Many popular web servers support async or reactive handlers • Ratpack’s been doing it for years now
  33. 33. @svpember Layers • Front-End • HTTP • Service Layer
  34. 34. @svpember Service Layer • Write Async Code!
  35. 35. @svpember Service Layer • Write Async Code! • java.util.concurrent
  36. 36. @svpember Service Layer • Write Async Code! • java.util.concurrent • GPars!
  37. 37. @svpember Service Layer • Write Async Code! • java.util.concurrent • GPars! • Project Reactor
  38. 38. @svpember Service Layer • Write Async Code! • java.util.concurrent • GPars! • Project Reactor • Reactive Streams
  39. 39. @svpember Service Layer • Write Async Code! • java.util.concurrent • GPars! • Project Reactor • Reactive Streams • Create an internal Message Bus
  40. 40. @svpember Layers • Front-End • HTTP • Service Layer • Messaging / Intra-Service comms
  41. 41. @svpember Messaging • Non Blocking I/O is vital! • Need an Asynchronous Message Broker • Need a dedicated Thread Pool (ExecutorService) • Message Flow:
  42. 42. @svpember
  43. 43. @svpember
  44. 44. @svpember Layers • Front-End • HTTP • Service Layer • Messaging / Intra-Service comms • Persistance
  45. 45. @svpember
  46. 46. Reactive JDBC Driver is Coming!
  47. 47. Tech Choices at Each Level
  48. 48. We prefer Libraries
  49. 49. Front-End
  50. 50. @svpember React • View Library for JS • Define Components that receive props and maintain state
  51. 51. React favors pushing properties ‘down’ through layers of components
  52. 52. @svpember React • View Library for JS • Define Components that receive props and maintain state • + Encourages reusable components
  53. 53. @svpember Stateful Components (“Containers”) • Maintains internal state of Component • Written as a class, with a variety of internal functions (e.g. click Handlers) • Not intended for re-use • May receive external State as props • Passes Props to Child Components • Simple Render functions that may concern layout • Children can be both Containers and Presentational • Refrain from ‘raw’ HTML (JSX), CSS, render() should use Presentational Components • Little-To-No Business Logic
  54. 54. @svpember Stateless Components (“Presentational”) • No State. Only receives Props. • Written as a single function (representing the render()) • Ideal if Presentational components are reusable • Potentially complex render functions. note: calling render() only affects DOM if props have changed for a component • No Business Logic
  55. 55. @svpember React • View Library for JS • Define Components that receive props and maintain state • + Encourages reusable components • + Shadow / Virtual DOM
  56. 56. @svpember React • View Library for JS • Define Components that receive props and maintain state • + Encourages reusable components • + Shadow / Virtual DOM • + Reacts to property changes
  57. 57. @svpember React • View Library for JS • Define Components that receive props and maintain state • + Encourages reusable components • + Shadow / Virtual DOM • + Reacts to property changes • + Has a massive ecosystem
  58. 58. React-Friendly Libraries for additional functionality
  59. 59. @svpember Redux • Library for handling global state, derived from Flux • One Immutable Store, but can allow for hierarchy (i.e. not flat shape) • Strict, Unidirectional Data Flow • Reducers, Actions, ActionCreators • Intended for Synchronous change operations • Hooks for Middleware / plugins
  60. 60. @svpember React • View Library for JS • Define Components that receive props and maintain state • + Encourages reusable components • + Shadow / Virtual DOM • + Reacts to property changes • + Has a massive ecosystem • - APIs change frequently
  61. 61. @svpember React • View Library for JS • Define Components that receive props and maintain state • + Encourages reusable components • + Shadow / Virtual DOM • + Reacts to property changes • + Has a massive ecosystem • - APIs change frequently • - Forces you to think in React
  62. 62. @svpember React: Use If… • You need a powerful View layer for your frontend • You appreciate the usefulness of composed, reusable View components • You have the mental agility to follow and keep up with the latest Javascript trends
  63. 63. HTTP
  64. 64. –Johnny Appleseed “Type a quote here.”
  65. 65. @svpember Ratpack • NIO HTTP Library • + Built on top of Netty • + Fast, lightweight • + Non-opinionated • + Excellent Testing support • + Excellent Gradle support • - Taking a while to adopt rxJava2 • - It’s I/O thread pool is Unbounded • - Non-obvious how to access registry / DI during a test
  66. 66. @svpember When to use Ratpack • You need NIO http support, but don’t want a full framework • You need to handle high levels of concurrent users • You’re comfortable going to a conference with many folks from the Grails team and talking about an alternative solution
  67. 67. Service Layer
  68. 68. @svpember RxJava • Reactive Streams implementation on the JVM, designed for communication across boundaries • + Makes Async / parallel programming ‘easy’ • + Promotes a highly functional, stream-oriented style • + Promotes stream-oriented programming • + Backpressure • + Composable & Cancelable • + Ideal for inputs of potentially infinite amounts of data • - Learning curve is steep / new programming paradigm • - can swallow exceptions if not careful
  69. 69. @svpember
  70. 70. @svpember
  71. 71. @svpember When to use RxJava • You need to write Async code • You have 1000s+ or potentially infinite events to process • You want to feel stupid • You comfortable going to a Groovy conference and telling people you don’t use GPars
  72. 72. Messaging
  73. 73. @svpember RabbitMQ • High Throughput Message Broker • + Complex and Powerful routing mechanisms • + High Availability, clustering, back pressure • + Durability / failure tolerance • + Easy to deploy / cluster • - not as fast as other message brokers • - Written in Erlang
  74. 74. @svpember When to use RabbitMQ: • You need Async message handling • You like having simple consumers and smart routing • You don’t mind being looked down upon by Kafka fans
  75. 75. Persistance
  76. 76. Come on, Async JDBC!
  77. 77. Overview and Demo
  78. 78. @svpember
  79. 79. @svpember Images • I’m sorry (Rain): https://imgur.com/gallery/J27yj3k • Spartans: www.300themovie.com/ • Colbert: https://giphy.com/gifs/stephen-colbert-report- hopeful-4KxeicCUTvhrW • The Flash: https://www.bleedingcool.com/2016/12/27/cws-flash-today- tomorrow-beyond/ • React Virtual Dom: https://www.youtube.com/watch?v=UH6dz6IGbK4
  80. 80. @svpember Links • Repo for the demo: https://github.com/spember/reactive-ratpack-demo

×