Slide 1

Slide 1 text

!1 Dreaming of Streaming with Reactive Programming Edson Yanaga, Red Hat @yanaga

Slide 2

Slide 2 text

!2 A stack to write Java apps Cloud Native Microservices Serverless

Slide 3

Slide 3 text

!3 Developer Joy Quarkus Benefits Supersonic Subatomic Java Unifies imperative and reactive Best of breed libraries and standards

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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. ...

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Events Messages Failures Is Reactive == Event-Driven ?

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

FROM EVENT-DRIVEN TO SYSTEMS

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

REACTIVE => RESPONSIVE

Slide 12

Slide 12 text

Asynchronous Message Passing REACTIVE => RESPONSIVE

Slide 13

Slide 13 text

Async != multi-thread Async == never-block

Slide 14

Slide 14 text

FROM HTTP 
 TO MESSAGING

Slide 15

Slide 15 text

HTTP => STRONG COUPLING

Slide 16

Slide 16 text

HTTP => UPTIME COUPLING

Slide 17

Slide 17 text

CB CB CB CB CB CB THE RISE OF CIRCUIT BREAKERS

Slide 18

Slide 18 text

Non-Blocking Message Passing Elasticity Resilience THE BENEFITS OF MESSAGING

Slide 19

Slide 19 text

Message Stream Publish/ Subscribe Request-Reply DATA AT REST => DATA IN MOTION

Slide 20

Slide 20 text

Supersonic. Subatomic. REACTIVE.

Slide 21

Slide 21 text

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}

Slide 22

Slide 22 text

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}

Slide 23

Slide 23 text

Coffee Shop Barista Coffee Shop Barista HTTP Board Kafka REACTIVE COFFEE SHOP https://github.com/cescoffier/quarkus-coffeeshop-demo Orders, Queue

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

@POST @Path("/http") public Beverage order(Order order) { return client.order(order); } @POST @Path("/async") public CompletionStage 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 orderAsync(Order order);

Slide 26

Slide 26 text

Coffee Shop Barista DEMO HTTP

Slide 27

Slide 27 text

Bridge imperative -> reactive DROP HTTP, SEND MESSAGES @Inject @Stream("orders") Emitter orders; public Order enqueue(Order order) { order.setOrderId(UUID.randomUUID().toString()); orders.send(jsonb.toJson(order)); return order; } Send “data” to the channel “orders”

Slide 28

Slide 28 text

@Incoming("orders") @Outgoing("queue") public CompletionStage 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

Slide 29

Slide 29 text

Coffee Shop Barista Board Queue Orders PROGRESS

Slide 30

Slide 30 text

@Inject @Stream("beverages") Publisher queue; @GET @Produces(MediaType.SERVER_SENT_EVENTS) public Publisher getQueue() { return queue; } Inject a stream Returns a stream PUSHING DATA TO SSE

Slide 31

Slide 31 text

Coffee Shop Barista Board Queue Orders DEMO

Slide 32

Slide 32 text

mp.messaging.smallrye-kafka.bootstrap.servers=localhost:9092 mp.messaging.smallrye-kafka.key.serializer=...StringSerializer mp.messaging.smallrye-kafka.value.serializer=...StringSerializer mp.messaging.outgoing.queue.connector=smallrye-kafka mp.messaging.outgoing.queue.acks=1 Direction MAPPING CHANNELS TO KAFKA TOPICS Channel Name 
 (= topic if not set)

Slide 33

Slide 33 text

Coffee Shop Barista Board Queue Orders BARISTAS TAKE BREAKS

Slide 34

Slide 34 text

Coffee Shop Baristas (Julie and Tom) Queue Orders RUSH HOUR! Board

Slide 35

Slide 35 text

SUMMARY

Slide 36

Slide 36 text

HTTP, Messaging, Streaming Quarkus Non-Blocking IO QUARKUS = {HTTP, MESSAGING, STREAMING}

Slide 37

Slide 37 text

WHAT ABOUT REACTIVE STREAMS? @Stream(“foo”) Emitter @Incoming(“foo”) @Outgoing(“bar”) @Stream(“bar”) Publisher @Outoing(“foo”) @Incoming(“bar”) Publisher Processor Subscriber Connector Connector

Slide 38

Slide 38 text

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

Slide 39

Slide 39 text

Non-Blocking Message Passing Elasticity Resilience REACTIVE SYSTEMS MADE EASY

Slide 40

Slide 40 text

Quark us Imperativ e Reactive CRUD, REST, CLI... Reactiv e System s Data Streamin g Supersonic, Subatomic, REACTIVE

Slide 41

Slide 41 text

!41 Thank you.