Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Going Reactive with gRPC

224 views

Published on

Going Reactive with gRPC

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Going Reactive with gRPC

  1. 1. GOING REACTIVE WITH GRPC ANDRES ALMIRAY @AALMIRAY ANDRESALMIRAY.COM
  2. 2. @aalmiray
  3. 3. @aalmiray JCP Executive Committee Associate Seat Committer Committer JSR377 Specification Lead
  4. 4. @aalmiray CONCEPTS
  5. 5. @aalmiray STATE Imperative Programming (Procedural) var a := b + c println a Declarative Programming (Functional) (println (sum(b, c))
  6. 6. @aalmiray TIME Imperative Programming var a := b + c println a Reactive Programming var a := b + c a.done( v -> println v)
  7. 7. @aalmiray 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. 8. @aalmiray 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. 9. @aalmiray 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. 10. @aalmiray 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. 11. @aalmiray 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)
  12. 12. @aalmiray DATA STREAMS
  13. 13. @aalmiray 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. 14. @aalmiray 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)
  15. 15. @aalmiray OPERATIONS (A SMALL SAMPLE OF)
  16. 16. @aalmiray HTTP://RXMARBLES.COM
  17. 17. @aalmiray HTTP://RXMARBLES.COM
  18. 18. @aalmiray HTTP://RXMARBLES.COM
  19. 19. @aalmiray HTTP://RXMARBLES.COM
  20. 20. @aalmiray HTTP://REACTIVEX.IO/RXJAVA/2.X/JAVADOC/INDEX.HTML
  21. 21. @aalmiray GRPC
  22. 22. @aalmiray 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.
  23. 23. @aalmiray
  24. 24. @aalmiray Go Java
  25. 25. @aalmiray RXGRPC https://github.com/salesforce/reactive-grpc Combines gRPC with Reactive Streams Encapsulates gRPC’s API Producers/Consumers only see Rx API
  26. 26. @aalmiray DEMO HTTPS://GITHUB.COM/AALMIRAY/HELLO-GRPC/
  27. 27. @aalmiray RESOURCES http://download.java.net/java/jdk9/docs/api/java/util/concurrent/Flow.ht ml http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Completab leFuture.html http://jdeferred.org/ http://andresalmiray.com/articles/jdeferred-simple-handling-of- promises-and-futures/ http://andresalmiray.com/articles/testing-rxjava2/ https://www.infoq.com/articles/rxjava2-by-example
  28. 28. @aalmiray REACTIVE PROGRAMMING IMPLIES AND PARADIGM CHANGE!
  29. 29. @aalmiray HTTP://ANDRESALMIRAY.COM/NEWSLETTER HTTP://ANDRESALMIRAY.COM/EDITORIAL
  30. 30. @aalmiray
  31. 31. THANK YOU! ANDRES ALMIRAY @AALMIRAY ANDRESALMIRAY.COM

×