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.

Reactor 3.0, a reactive foundation for java 8 and Spring

5,960 views

Published on

An introduction to the new facilities of Reactor 3 and its core focus : consumable Reactive Streams for Java 8.

Published in: Software
  • Please give a link for sound or video, thx
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Reactor 3.0, a reactive foundation for java 8 and Spring

  1. 1. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor 3. 
 Reactive Foundation for Java 8 and Spring Stephane Maldini @smaldini
  2. 2. Reactive ?
  3. 3. Reactive ?
  4. 4. Publisher Subscriber Reactive Streams
 reactive-streams.org
  5. 5. Publisher Subscriber Reactive Streams
 reactive-streams.org Standard definition
  6. 6. Publisher Subscriber Reactive Streams
 reactive-streams.org Standard definition 0..N Data 
 + 0..1 (Error | Complete)
  7. 7. Publisher Subscriber Backpressure Reactive Streams
 reactive-streams.org Standard definition 0..N Data 
 + 0..1 (Error | Complete)
  8. 8. Publisher Subscriber Backpressure Reactive Streams
 reactive-streams.org Standard definition 0..N Data 
 + 0..1 (Error | Complete)
  9. 9. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor Core provides for a minimalist set of Reactive Streams ready 
 generators and transformers 4
  10. 10. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor Core provides for a minimalist set of Reactive Streams ready 
 generators and transformers 4 WHY ?
  11. 11. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 DIY Reactive Streams Publisher<User> rickSanchez = userRepository.findUser(“rick”);
  12. 12. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 DIY Reactive Streams Publisher<User> rickSanchez = userRepository.findUser(“rick”); Produce User when ready
  13. 13. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 DIY Reactive Streams Publisher<User> rickSanchez = userRepository.findUser(“rick”); Might produce 0, 1 or N Users ! Produce User when ready
  14. 14. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 DIY Reactive Streams Publisher<User> rickSanchez = userRepository.findUser(“rick”); Might produce 0, 1 or N Users ! Produce User when ready rickSanchez.subscribe(new Subscriber<User>(){ … });
  15. 15. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 5 DIY Reactive Streams Publisher<User> rickSanchez = userRepository.findUser(“rick”); Might produce 0, 1 or N Users ! Produce User when ready Callback for start, result, error or complete rickSanchez.subscribe(new Subscriber<User>(){ … });
  16. 16. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ DIY Reactive Streams 6
  17. 17. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ DIY Reactive Streams 6 Can I have an API ?
  18. 18. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ DIY Reactive Streams - top issues • Should Work with RS TCK • Address reentrance • Address thread safety • Address efficiency • Address state • For Many-To-One flows, implement your own merging operation • For One-To-Many lows, implement your own broadcasting operation • …. 7
  19. 19. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ DIY Reactive Streams - top issues • Should Work with RS TCK • Address reentrance • Address thread safety • Address efficiency • Address state • For Many-To-One flows, implement your own merging operation • For One-To-Many lows, implement your own broadcasting operation • …. 7
  20. 20. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 8
  21. 21. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 years to mature 9 R e a c t i v e S t r e a m s C o m m o n s I P C A D D O N S S p r i n g R x C O R E 2013: 1.x 2014: 2.x 2016: 3.0
  22. 22. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 years to mature 9 R e a c t i v e S t r e a m s C o m m o n s I P C A D D O N S S p r i n g R x C O R E Existential questions 2013: 1.x 2014: 2.x 2016: 3.0
  23. 23. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 years to mature 9 R e a c t i v e S t r e a m s C o m m o n s I P C A D D O N S S p r i n g R x C O R E Existential questions 2013: 1.x 2014: 2.x 2016: 3.0 Microservices become the norm
  24. 24. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3 years to mature 9 R e a c t i v e S t r e a m s C o m m o n s I P C A D D O N S S p r i n g R x C O R E Existential questions 2013: 1.x 2014: 2.x 2016: 3.0 Microservices become the norm Rocky style revival
  25. 25. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3x Influences and Collaborations 10 R e a c t i v e S t r e a m s C o m m o n s I P C A D D O N S S p r i n g R x C O R E
  26. 26. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3x Influences and Collaborations 10 R e a c t i v e S t r e a m s C o m m o n s I P C A D D O N S S p r i n g R x C O R E
  27. 27. Flux
  28. 28. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Flux.just("red", "white", "blue")
 .flatMap(carRepository::findByColor)
 .collect(Result::new, Result::add)
 .doOnNext(Result::stop)
 .subscribe(doWithResult); A smarter Publisher ? Flux ! 12
  29. 29. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Flux.just("red", "white", "blue")
 .flatMap(carRepository::findByColor)
 .collect(Result::new, Result::add)
 .doOnNext(Result::stop)
 .subscribe(doWithResult); A smarter Publisher ? Flux ! 12 interface CarRepository { Flux<Car> findByColor(String color); }
  30. 30. Mono
  31. 31. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Mono, push/pull CompletionStage 14 Mono.delayMillis(3000)
 .map(d -> "Spring 4")
 .or(Mono.delayMillis(2000).map(d -> "Spring 5"))
 .then(t -> Mono.just(t+ " world"))
 .elapsed()
 .block();
  32. 32. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Mono, push/pull CompletionStage 14 Mono.delayMillis(3000)
 .map(d -> "Spring 4")
 .or(Mono.delayMillis(2000).map(d -> "Spring 5"))
 .then(t -> Mono.just(t+ " world"))
 .elapsed()
 .block(); Non!
  33. 33. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Mono, push/pull CompletionStage 15 Mono.delayMillis(3000)
 .map(d -> "Spring 4")
 .or(Mono.delayMillis(2000).map(d -> "Spring 5"))
 .then(t -> Mono.just(t+ " world"))
 .elapsed()
 .subscribe();
  34. 34. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Mono, push/pull CompletionStage 15 Mono.delayMillis(3000)
 .map(d -> "Spring 4")
 .or(Mono.delayMillis(2000).map(d -> "Spring 5"))
 .then(t -> Mono.just(t+ " world"))
 .elapsed()
 .subscribe(); Oui!
  35. 35. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Non Blocking and RS types around 16 Type Semantic /Library Java 8 Reactive Streams /Java 9 RxJava1
 (java6) Reactor3
 (java8) RxJava2
 (java6) 0 or 1 result CompletableFuture<T> Publisher<T> Observable<T> Mono<T> Maybe<T> 0 or N results Publisher<T> Observable<T> Flux<T> Observable<T>
 Flowable<T> 1 result CompletableFuture<T> Publisher<T> Single<T> Mono<T> Single<T> No result CompletableFuture<Void> Publisher<Void> Completable Mono<Void> Completable *Reactive Streams types are in bold **Akka Streams is also a notable RS implementor
  36. 36. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 17 3x Simpler API
  37. 37. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ONE JAR
 reactor-core.jar 17 3x Simpler API
  38. 38. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ONE JAR
 reactor-core.jar 17 3x Simpler API
  39. 39. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ONE JAR
 reactor-core.jar 17 3x Simpler API Where Flux and Mono live
  40. 40. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ ONE JAR
 reactor-core.jar 17 3x Simpler API Where Flux and Mono live Make task execution great again and FIFO
  41. 41. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Execution Model Freedom 18 Synchronous Asynchronous Scheduler / Scheduler.Worker
  42. 42. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Execution Model Freedom 19 Publisher Subscriber
  43. 43. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Execution Model Freedom 19 Publisher Subscriber Thread: MAIN Thread: MAIN
  44. 44. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Execution Model Freedom 20 Publisher Subscriber +publishOn()
 Thread: Worker A Thread: Worker A
  45. 45. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Execution Model Freedom 21 Publisher Subscriber Thread: Worker B +subscribeOn() Thread: Worker B
  46. 46. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Execution Model Freedom 22 Publisher Subscriber +publishOn()
 Thread: Worker A +subscribeOn() Thread: Worker B
  47. 47. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 3x more focus on Javadoc 23 http://projectreactor.io/core/docs/api
  48. 48. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learning to Flux & Mono 24
  49. 49. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learning to Flux & Mono 24 https://spring.io/blog/2016/06/07/notes-on- reactive-programming-part-i-the-reactive- landscape https://spring.io/blog/2016/06/13/notes-on- reactive-programming-part-ii-writing-some-code https://spring.io/blog/2016/07/20/notes-on- reactive-programming-part-iii-a-simple-http-server- application
  50. 50. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Learning to Flux & Mono 24 https://spring.io/blog/2016/06/07/notes-on- reactive-programming-part-i-the-reactive- landscape https://spring.io/blog/2016/06/13/notes-on- reactive-programming-part-ii-writing-some-code https://spring.io/blog/2016/07/20/notes-on- reactive-programming-part-iii-a-simple-http-server- application Just browse spring.io/blog already
  51. 51. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Bridge Existing Asynchronous Code Mono<String> response = Mono.create(sink -> {
 HttpListener listener = event -> {
 if (event.getResponseCode() >= 400) {
 sink.error(new RuntimeExeption("Failed"));
 } else {
 String body = event.getBody();
 if (body.isEmpty()) {
 sink.success();
 } else {
 sink.success(body.toLowerCase());
 }
 }
 };
 
 client.addListener(listener);
 
 emitter.setCancellation(() -> client.removeListener(listener));
 }); • 25
  52. 52. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Bridge Existing Asynchronous Code Mono<String> response = Mono.create(sink -> {
 HttpListener listener = event -> {
 if (event.getResponseCode() >= 400) {
 sink.error(new RuntimeExeption("Failed"));
 } else {
 String body = event.getBody();
 if (body.isEmpty()) {
 sink.success();
 } else {
 sink.success(body.toLowerCase());
 }
 }
 };
 
 client.addListener(listener);
 
 emitter.setCancellation(() -> client.removeListener(listener));
 }); • 25 Also exists for Flux of N items
  53. 53. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Debug Mode 26 215 Hooks.onOperator(op -> op.operatorStacktrace()); 216 try { 217 Mono.just(1) 218 .map(d -> { 219 throw new RuntimeException(); 220 }) 221 .filter(d -> true) 222 .timestamp() 223 .elapsed() 224 .map(d -> d) 225 .block(); 226 } 227 catch(Exception e){ 228 e.printStackTrace(); 229 } 230 finally { 231 Hooks.resetOnOperator(); 232 }
  54. 54. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Debug Mode 26 215 Hooks.onOperator(op -> op.operatorStacktrace()); 216 try { 217 Mono.just(1) 218 .map(d -> { 219 throw new RuntimeException(); 220 }) 221 .filter(d -> true) 222 .timestamp() 223 .elapsed() 224 .map(d -> d) 225 .block(); 226 } 227 catch(Exception e){ 228 e.printStackTrace(); 229 } 230 finally { 231 Hooks.resetOnOperator(); 232 } Capture stack for each operator declared after
  55. 55. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Debug Mode 26 215 Hooks.onOperator(op -> op.operatorStacktrace()); 216 try { 217 Mono.just(1) 218 .map(d -> { 219 throw new RuntimeException(); 220 }) 221 .filter(d -> true) 222 .timestamp() 223 .elapsed() 224 .map(d -> d) 225 .block(); 226 } 227 catch(Exception e){ 228 e.printStackTrace(); 229 } 230 finally { 231 Hooks.resetOnOperator(); 232 } Capture stack for each operator declared after Assembly trace from producer [reactor.core.publisher.MonoMapFuseable] : reactor.core.publisher.Mono.map(Mono.java:1795) reactor.HooksTest.testTrace2(HooksTest.java:218) Composition chain until failing Operator : |_ Mono.map(HooksTest.java:218) |_ Mono.filter(HooksTest.java:221) |_ Mono.timestamp(HooksTest.java:222) |_ Mono.elapsed(HooksTest.java:223) |_ Mono.map(HooksTest.java:224)
  56. 56. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Create Gateways to Flux And Mono 27 EmitterProcessor<Integer> processor = EmitterProcessor.create();
 
 int n = 100_000;
 processor.publishOn(Schedulers.single())
 .subscribe(someService::handleData);
 
 BlockingSink<Integer> session = processor.connectSink();
 
 for (int i = 0; i < n; i++) {
 while (!session.emit(i).isOk()) {
 if (session.hasFailed()) {
 throw session.getError();
 } //fake throttling Thread.sleep(1);
 }
 }
 session.finish(); • EmitterProcessor
  57. 57. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Create Gateways to Flux And Mono 27 EmitterProcessor<Integer> processor = EmitterProcessor.create();
 
 int n = 100_000;
 processor.publishOn(Schedulers.single())
 .subscribe(someService::handleData);
 
 BlockingSink<Integer> session = processor.connectSink();
 
 for (int i = 0; i < n; i++) {
 while (!session.emit(i).isOk()) {
 if (session.hasFailed()) {
 throw session.getError();
 } //fake throttling Thread.sleep(1);
 }
 }
 session.finish(); • EmitterProcessor Backpressure Companion
  58. 58. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ EmitterProcessor<Integer> processor = EmitterProcessor.create();
 
 int n = 100_000;
 processor.publishOn(Schedulers.single())
 .subscribe(someService::handleData);
 
 BlockingSink<Integer> session = processor.connectSink();
 
 for (int i = 0; i < n; i++) {
 while (!session.emit(i).isOk()) {
 if (session.hasFailed()) {
 throw session.getError();
 } Thread.sleep(1); //fake throttling
 }
 }
 session.finish(); • Create Gateways to Flux And Mono 28 EmitterProcessor
  59. 59. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Operation Fusion • Reactor has a mission to limit the overhead in stack and message passing • 2 key categories : • “Macro Fusion” : merge operators in one (assembly time) • “Micro Fusion” : avoid queue creation and short circuit where possible request lifecycle. 29
  60. 60. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Starve CPU’s with ParallelFlux… 30 Flux.range(1, 100000)
 .parallel(3)
 .runOn(Schedulers.parallel())
 .collect(ArrayList::new, ArrayList::add)
 .sequential()
 .reduce(0, (a, b) -> a + b.size())
 .subscribeWith(TestSubscriber.create())
 .await(Duration.ofSeconds(5))
 .assertValues(100_000)
 .assertNoError()
 .assertComplete(); •
  61. 61. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Starve CPU’s with ParallelFlux… 30 Flux.range(1, 100000)
 .parallel(3)
 .runOn(Schedulers.parallel())
 .collect(ArrayList::new, ArrayList::add)
 .sequential()
 .reduce(0, (a, b) -> a + b.size())
 .subscribeWith(TestSubscriber.create())
 .await(Duration.ofSeconds(5))
 .assertValues(100_000)
 .assertNoError()
 .assertComplete(); • x3
  62. 62. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Efficient and micro bench ready 31 https://github.com/akarnokd/akarnokd-misc/tree/master/src/jmh/java/hu/akarnokd/comparison
  63. 63. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Efficient and micro bench ready 31 https://github.com/akarnokd/akarnokd-misc/tree/master/src/jmh/java/hu/akarnokd/comparison
  64. 64. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Efficient and micro bench ready 31 https://github.com/akarnokd/akarnokd-misc/tree/master/src/jmh/java/hu/akarnokd/comparison
  65. 65. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Bridge Fabulous RxJava 32
  66. 66. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Bridge Fabulous RxJava 32 RxJava1Adapter
  67. 67. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Bridge Java 9 Reactive Streams 33
  68. 68. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Bridge Java 9 Reactive Streams 33 JdkFlowAdapter
  69. 69. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Play with Reactor Core .NET 34
  70. 70. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Play with Reactor Core .NET 34 https://www.nuget.org/packages/Reactor.Core/
  71. 71. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Backpressure for JS: Reactor Core TypeScript 35
  72. 72. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Backpressure for JS: Reactor Core TypeScript 35 https://www.npmjs.com/package/reactor-core-js
  73. 73. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ EVERYTHING REACTIVE ? 36
  74. 74. µ Service A Data Cloud Messaging Web
  75. 75. Service B Message
 Broker Datastore 20 ms 50 ms 150 ms 250 ms 20 ms 15 ms 3 ms GATEWAY µ Service A
  76. 76. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Reactor Ecosystem roadmap 39 Reactor Netty Reactor IPC Spring Framework Spring 5, 
 Spring Cloud Stream, 
 Spring Integration,
 Spring Data, 
 Spring Boot, 
 Spring Cloud, 
 Spring Security,
 … Reactor Kafka Extra add-ons
 dashboard, bus, codecs, more operations & schedulers… Reactor Redis Reactor Aeron
  77. 77. Spring Framework 5
  78. 78. Spring Web MVC @Controller, @RequestMapping Servlet API Servlet Container
  79. 79. Spring Web MVC @Controller, @RequestMapping Servlet API Servlet Container Reactive Non-blocking …
  80. 80. Spring Web MVC Spring Web Reactive @Controller, @RequestMapping Servlet API Servlet Container
  81. 81. Spring Web MVC Spring Web Reactive @Controller, @RequestMapping Servlet API Servlet Container Reactive HTTP
  82. 82. Spring Web MVC Spring Web Reactive @Controller, @RequestMapping Servlet API Servlet Container Reactive HTTP Servlet 3.1 Container
  83. 83. Spring Web MVC Spring Web Reactive @Controller, @RequestMapping Servlet API Servlet Container Reactive HTTP Servlet 3.1 ContainerServlet 3.1, Netty
  84. 84. Spring Web MVC Spring Web Reactive @Controller, @RequestMapping Servlet API Servlet Container Reactive HTTP Servlet 3.1 ContainerServlet 3.1, Netty, Undertow
  85. 85. Non-Blocking HTTP GET
  86. 86. Non-Blocking HTTP POST
  87. 87. WebClient Scatter/Gather
  88. 88. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ 51 SpringBootApplication
 @EnableBinding(Processor.class)
 public class WordCountApplication {
 
 @StreamListener
 @Output("output")
 public Flux<WordCount> countWords(@Input("input") Flux<String> words) {
 return words.window(ofSeconds(5), ofSeconds(1))
 .flatMap(window -> window.groupBy(word -> word)
 .flatMap(group -> group.reduce(0, (counter, word) -> counter + 1)
 .map(count -> new WordCount(group.key(), count))));
 } } Spring Cloud Stream: 
 Stateful processors
  89. 89. Boot Data Cloud IntegrationSecurity Reactive Efforts
  90. 90. Unless otherwise indicated, these slides are © 2013-2016 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ @ProjectReactor http://github.com/reactor http://projectreactor.io Extra Slideware: www.slideshare.net/SpringCentral/imperative-to-reactive-web-applications www.slideshare.net/SpringCentral/designing-implementing-and-using-reactive-apis http://www.slideshare.net/RobHarrop/going-reactive-63425158

×