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.

Reactive Web Applications

2,641 views

Published on

Recorded at SpringOne2GX 2015
Presenters: Stephane Maldini and Rossen Stoyanchev
Web / Javascript Track

In our previous talk "Intro to Reactive Programming" we defined reactive programming and provided details around key initiatives such as Reactive Streams and ReactiveX. In this talk we'll focus on where we are today with building reactive web applications. We'll take a look at the choice of runtimes, how Reactive Streams may be applied to network I/O, and what the programming model may look like. While this is a forward looking talk, we'll spend plenty of time demoing code built with with back-pressure ready libraries available today.

Published in: Technology

Reactive Web Applications

  1. 1. Unless otherwise indicated, these slides are © 2013-2014 Pivotal Software, Inc. and licensed under a Creative Commons Attribution-NonCommercial license: http://creativecommons.org/licenses/by-nc/3.0/ Stephane Maldini Rossen Stoyanchev
  2. 2. About the Speakers • • •
  3. 3. ReadListener WriteListener ServletInputStream ServletOutputStream • isReady read() write() •
  4. 4. request.getParameters()
  5. 5. java.util.concurrent
  6. 6. onSubscribe onNext* (onError|onComplete)? Publisher Subscriber Subscription request(n) cancel()
  7. 7. public interface ServerHttpRequest extends HttpRequest { Publisher<byte[]> getBody(); } public interface ServerHttpResponse extends HttpMessage { Publisher<Void> writeWith(Publisher<byte[]> publisher); }
  8. 8. public interface ServerHttpRequest extends HttpRequest { InputStream getBody(); } public interface ServerHttpResponse extends HttpMessage { OutputStream getBody(); }
  9. 9. ? ?
  10. 10. Publisher<T> <T>
  11. 11. Publisher
  12. 12. Publisher Streams.just('a' 'b' 'c') .take(2) .map(Character::toUpperCase) .consume(System.out::println);
  13. 13. Observable.just('a', 'b', 'c') .take(2) .map(Character::toUpperCase) .subscribe(System.out::println);
  14. 14. Observable-Observer Publisher-Subscriber
  15. 15. Demo: HeadFirst
  16. 16. rx.Observable rx.Subscriber
  17. 17. Publisher Subscriber
  18. 18. ,
  19. 19. Max(request) == Queue.capacity()
  20. 20. Publisher
  21. 21. Subscriber
  22. 22. Subscription.request(n)
  23. 23. @RequestMapping("/capitalize") @ResponseBody public Publisher<Person> capitalize(@RequestBody Publisher<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); } Publisher
  24. 24. @RequestMapping("/capitalize") @ResponseBody public Stream<Person> capitalize(@RequestBody Stream<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); } Stream
  25. 25. @RequestMapping("/capitalize") @ResponseBody public Observable<Person> capitalize(@RequestBody Observable<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); } Observable
  26. 26. function() { StreamService.connect("stream") .flatMap(unpackCsv) .subscribe(updateUI, logError, logComplete); } var unpackCsv = function (ev) { return Rx.Observable.from(ev.data ? ev.data.split("n") : []) .filter(discardEmpty) .map(csvToJson) }
  27. 27. Learn More. Stay Connected. Thank You for Listening! @smaldini / @rstoya05

×