Reactive Streams

Preview:

Citation preview

endava.com

QUALITY. PRODUCTIVITY. INNOVATION.

Reactive StreamsBy Dorin Cobzac

2

2 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution•Conclude the Findings

3

3 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution•Conclude the Findings

4

4 QUALITY. PRODUCTIVITY. INNOVATION.

Every Minute:• Facebook users share nearly 2.5 million pieces of content.• Twitter users tweet nearly 300,000 times.• Instagram users post nearly 220,000 new photos.• Apple users download nearly 50,000 apps.• Email users send over 200 million messages.

HUGE amounts of Data

5

5 QUALITY. PRODUCTIVITY. INNOVATION.

• … applications• … network nodes• … CPUs• … threads• … actors (actor systems)

Distributed between …

6 QUALITY. PRODUCTIVITY. INNOVATION.

Distribution is trending

7 QUALITY. PRODUCTIVITY. INNOVATION.

How to handling HUGE data streams across distributed systems?

8

8 QUALITY. PRODUCTIVITY. INNOVATION.

Solutions?

9 QUALITY. PRODUCTIVITY. INNOVATION.

• Making usual calls and wait for responses• Push to a Queue and risk losing messages• Use distributed queues

10 QUALITY. PRODUCTIVITY. INNOVATION.

OR

11

11 QUALITY. PRODUCTIVITY. INNOVATION.

Go Reactive

12

12 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

13

13 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

14

14

What is a Stream?

QUALITY. PRODUCTIVITY. INNOVATION.

15

15 QUALITY. PRODUCTIVITY. INNOVATION.

… but seriously, what is a Stream?

16

16

• … may not have a start• … may not have an end• … doesn’t have a size• … its elements are retrieved/computed “on-the-spot”

A Stream is a Data source that …

QUALITY. PRODUCTIVITY. INNOVATION.

17

17

Reactive Stream basics?

QUALITY. PRODUCTIVITY. INNOVATION.

18

18

Data Flow: Fast Producer

QUALITY. PRODUCTIVITY. INNOVATION.

19

19

Data Flow: Slow Producer

QUALITY. PRODUCTIVITY. INNOVATION.

20

20

Data Flow: Self-regulating

QUALITY. PRODUCTIVITY. INNOVATION.

Automatically switches between being consumer and producer driven

21

21

Data Flow: Asynchronous

QUALITY. PRODUCTIVITY. INNOVATION.

The communication between components is asynchronous!

22

22

Data Flow: Back-pressure

QUALITY. PRODUCTIVITY. INNOVATION.

23

23

Data Flow: Back-pressure

QUALITY. PRODUCTIVITY. INNOVATION.

24

24

Stream Operations: Split

QUALITY. PRODUCTIVITY. INNOVATION.

25

25

Stream Operations: Merge

QUALITY. PRODUCTIVITY. INNOVATION.

26

26

Other Stream Operations

QUALITY. PRODUCTIVITY. INNOVATION.

• Filter certain elements from a stream• Transform one or more elements in a stream• Match certain elements based on some complex logic and/or order

27

27

Reactive Streams working together

QUALITY. PRODUCTIVITY. INNOVATION.

28

28 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

29

29 QUALITY. PRODUCTIVITY. INNOVATION.

•Define the Problem•Describe the Solution• Conclude the Findings

30

30

Reactive Streams: Advantages

QUALITY. PRODUCTIVITY. INNOVATION.

• Effective resource consumption• Flexibility• Inter-operability

31

31

Reactive Streams: Caveat

QUALITY. PRODUCTIVITY. INNOVATION.

Go fully Reactive, or you’re not getting the full benefits

32

32

Reactive Streams: Relevance

QUALITY. PRODUCTIVITY. INNOVATION.

Internet of Things is hereAre you ready?

33

33 QUALITY. PRODUCTIVITY. INNOVATION.

Thank you!

34 QUALITY. PRODUCTIVITY. INNOVATION.

35

35

Reactive Stream Flavors

QUALITY. PRODUCTIVITY. INNOVATION.

1. Reactive Streams Specification v.1- Released on 30 April 2015- Contributions from Pivotal, Redhat, TypeSafe, Netflix- Includes a Technology Compatibility Kit- Only on JVM ecosystem (for now)

2. Reactive Extensions API- Multiple implementations (including .Net and Ruby)- A Netflix Original Production- Reactive Streams spec v.0.9 (kind-of)- Interops through RxJava Reactive Streams project

36

36 QUALITY. PRODUCTIVITY. INNOVATION.

public interface Publisher<T> { public void subscribe(Subscriber<? super T> s);

} public interface Subscriber<T> {

public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete();

}

public interface Subscription { public void request(long n); public void cancel();

}

public interface Processor<T, R> extends Subscriber<T>, Publisher<R>

Reactive Streams Specification v.1

37

37

Reactive Streams Specification v.1

QUALITY. PRODUCTIVITY. INNOVATION.

38

38

Reactive Extensions API (short)

QUALITY. PRODUCTIVITY. INNOVATION.

public class Observable<T> { public static Observable<T> create(OnSubscriber<T> s);public Subscription<T> subscribe(Observer<? super T> subscriber);

} public interface Observer<T> {

public void onNext(T t); public void onError(Throwable t); public void onComplete();

}

Recommended