Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dreaming of Streaming with Reactive Programming

Dreaming of Streaming with Reactive Programming

Reactive programming, Reactive Extensions, Reactive Streams, reactive systems, Reactive Manifesto… Do you know what they mean? Do you know why it matters?

Learn about reactive and why it matters in this new cloud-native era. We’ll use live coding demos to explain how to be reactive and benefit from this brave new streaming world.

Edson Yanaga

July 24, 2019
Tweet

More Decks by Edson Yanaga

Other Decks in Technology

Transcript

  1. !3 Developer Joy Quarkus Benefits Supersonic Subatomic Java Unifies imperative

    and reactive Best of breed libraries and standards
  2. System eXtensions Programming Manifesto Streams Asynchrony Resilience Elasticity Back-Pressure Spreadsheets

    Actor Events Messages Data Flows RX Java Responsiveness Fibers Non-Blocking Reactor Spring MicroProfile REACTIVE ALL THE THING
  3. reactive | rēˈaktiv | adjective showing a response to a

    stimulus: pupils are reactive to light. • acting in response to a situation rather than creating or controlling it: a proactive rather than a reactive approach. • having a tendency to react chemically: nitrogen dioxide is a highly reactive gas. • Physiology showing an immune response to a specific antigen. ...
  4. reactive | rēˈaktiv | adjective showing a response to a

    stimulus: pupils are reactive to light. • acting in response to a situation rather than creating or controlling it: a proactive rather than a reactive approach. • having a tendency to react chemically: nitrogen dioxide is a highly reactive gas. • Physiology showing an immune response to a specific antigen. ... • Software application reacting to stimuli such as user inputs, messages, and failures
  5. Build concurrent applications Reactive programming Reactive streams Non-Blocking Asynchronous Event-Driven

    => Concurrent Applications Non-Blocking IO (Netty) Reactive Framework Application Code Callbacks, RX Java, Reactor, Co-routines... } 1 Thread -> n concurrent tasks
  6. Build responsive distributed systems Reactive Systems Elasticity, Resilience, Messages Build

    concurrent applications Reactive programming Reactive streams Non-Blocking Asynchronous TWO SIDES OF THE SAME COIN
  7. Messaging / Streaming Quarkus Application Code Container Host / Operating

    System Async HTTP Messaging Quarkus Application Code Container Host / Operating System Messaging Middleware QUARKUS = {HTTP, MESSAGING, STREAMING}
  8. MicroProfile Reactive Messaging Quarkus Application Code Container Host / Operating

    System Async HTTP Messaging Quarkus Application Code Container Host / Operating System Messaging Middleware QUARKUS = {HTTP, MESSAGING, STREAMING}
  9. Coffee Shop Barista Coffee Shop Barista HTTP Board Kafka REACTIVE

    COFFEE SHOP https://github.com/cescoffier/quarkus-coffeeshop-demo Orders, Queue
  10. Coffee Shop Barista HTTP WHAT’S THE PROBLEM WITH SYNCHRONOUS On

    a peak of load • Concurrency limited by the coffee shop thread pool • Must scale up the number of baristas • Require some kind of load-balancer • COLD COFFEE or NO COFFEE On failing barista • Orders are lost • NO COFFEE On slow barista • Coffee Shop gets slow • COLD COFFEE
  11. @POST @Path("/http") public Beverage order(Order order) { return client.order(order); }

    @POST @Path("/async") public CompletionStage<Beverage> order(Order order) { return client.orderAsync(order); } FROM SYNC TO ASYNC HTTP Non-Blocking Thread released @POST @Produces("application/json") @Consumes("application/json") Beverage order(Order order); @POST @Produces("application/json") @Consumes("application/json") CompletionStage<Beverage> orderAsync(Order order);
  12. Bridge imperative -> reactive DROP HTTP, SEND MESSAGES @Inject @Stream("orders")

    Emitter<String> orders; public Order enqueue(Order order) { order.setOrderId(UUID.randomUUID().toString()); orders.send(jsonb.toJson(order)); return order; } Send “data” to the channel “orders”
  13. @Incoming("orders") @Outgoing("queue") public CompletionStage<String> prepare(String message) { Order order =

    fromJson(message, Order.class); return makeIt(order) .thenApply(beverage -> PreparationState.ready(order, beverage) ); } Process data async* * Many other options available to produce, process or consume data Read from “orders” Write to “queue” PROCESSING MESSAGES
  14. WHAT ABOUT REACTIVE STREAMS? @Stream(“foo”) Emitter @Incoming(“foo”) @Outgoing(“bar”) @Stream(“bar”) Publisher

    @Outoing(“foo”) @Incoming(“bar”) Publisher Processor Subscriber Connector Connector
  15. BRIDGE REACTIVE AND IMPERATIVE @Stream(“foo”) Emitter @Incoming(“foo”) @Outgoing(“bar”) @Stream(“bar”) Publisher

    @Outoing(“foo”) @Incoming(“bar”) Publisher Processor Subscriber Connector Connector
  16. Quark us Imperativ e Reactive CRUD, REST, CLI... Reactiv e

    System s Data Streamin g Supersonic, Subatomic, REACTIVE