The document discusses going reactive with gRPC. It covers reactive concepts like sync vs async, futures and promises, data streams, and RxJava operations. It then discusses gRPC as a modern RPC framework and shows how rxgrpc can encapsulate gRPC's API to expose a reactive streams API to producers and consumers. It includes a demo of using rxgrpc with a hello world gRPC example.
7. @aalmiray | andresalmiray.com
Sync vs async
Synchronous operations block the flow until they yield a
result (success or error).
Asynchronous operations DO NOT block the flow, rather
they allow the program to continue. Results (or errors) will
be handled at a later point in time, typically using
functions (callbacks).
8. @aalmiray | andresalmiray.com
Futures and promises
They describe an object that acts as mediator for a value
that may be unknown at init time.
The terms Future and Promise are normally used
interchangeably but there’s a difference:
• A Future is a read-only reference of the expected value.
• A Promise is a write-once container that sets the value of
the Future.
https://en.wikipedia.org/wiki/Futures_and_promises
9. @aalmiray | andresalmiray.com
Futures and promises
Futures in Java are synchronous, this can be
demonstrated by the following method signatures found
in java.util.concurrent.Future
V get()
V get(long timeout, TimeUnit unit)
10. @aalmiray | andresalmiray.com
Futures and promises
Java 8 added a new type, CompletableFuture, that
implements CompletableStage, which in turns defines
the contract of a Promise, such as
thenAccept(Consumer<? Super T> action)
whenComplete(BiConsumer<? super T,? super Throwable>
action)
exceptionally(Function<Throwable,? extends T> fn)
… and many others
11. @aalmiray | andresalmiray.com
Futures and promises
JDeferred offers a different API that allows better function
composition
Promise<D, F, P> then(DoneCallback<D> doneCallback)
Promise<D, F, P> done(DoneCallback<D> callback)
Promise<D, F, P> fail(FailCallback<F> callback)
Promise<D, F, P> always(AlwaysCallback<D, F> callback)
13. @aalmiray | andresalmiray.com
Data streams
A sequence of values calculated over time.
Values are emitted when ready; they are computed without blocking
consumers.
Consumers listen to changes in the data stream and react to said
changes (hence the name Reactive Programming).
Push vs pull model.
14. @aalmiray | andresalmiray.com
Observable/observer
Data streams are of type Observable while consumer are
of type Observer.
The Observable type exposes multiple operations that
allow value composition, combinations, filtering, and
other value transformations.
NOTE: many operations from RxJava/Reactor generate a
new Observable (decorator pattern)
22. @aalmiray | andresalmiray.com
https://grpc.io/
gRPC is a modern, open source, high-performance
remote procedure call (RPC) framework that can run
anywhere. It enables client and server applications to
communicate transparently, and makes it easier to build
connected systems.