Advertisement

Reactive Programming in Spring 5

Nov. 20, 2015
Advertisement

More Related Content

Slideshows for you(20)

Advertisement
Advertisement

Reactive Programming in Spring 5

  1. Reactive Programming in Spring 5 Arjen Poutsma Pivotal
  2. About Arjen • Twenty years of experience in Enterprise Software Development • Joined SpringSource in 2005 • Development lead of Spring Web Services, Spring REST support, Spring Scala • Working on Spring 5
  3. Agenda • Reactive Systems • Reactive Streams • RxJava • Reactor • Reactive Programming in Spring 5
  4. Reactive Systems
  5. Reactive Manifesto Responsive Message Driven ResilientElastic
  6. Reactive Manifesto • Responsive • Rapid • Consistent • Resilient • Replication • Isolation • Elastic • Scaling • No bottlenecks • Message Driven • Async • Back-pressure
  7. Reactive Streams
  8. Reactive Streams Spec • Focus on Interoperability • No operators • Wide support • Akka,Vert.x, RxJava, Ratpack • JDK 9 Flow in java.util.concurrent
  9. Publisher Subscriber
  10. Publisher Subscribersubscribe
  11. Publisher Subscriber
  12. Publisher Subscriber
  13. Publisher Subscriber onSubscribe Subscription
  14. Publisher Subscriber Subscription
  15. Subscription Publisher Subscriber
  16. Subscription Publisher Subscriber request 2
  17. Subscription Publisher Subscriber 2
  18. Subscription Publisher Subscriber 2
  19. Subscription Publisher Subscriber onNext 1
  20. Subscription Publisher Subscriber 1
  21. Subscription Publisher Subscriber onNext 0
  22. Subscription Publisher Subscriber 0
  23. Subscription Publisher Subscriber request 5
  24. Subscription Publisher Subscriber 5
  25. Subscription Publisher Subscriber 5
  26. Subscription Publisher Subscriber onNext 4
  27. Subscription Publisher Subscriber 4
  28. Subscription Publisher Subscriber onNext 3
  29. Subscription Publisher Subscriber 3
  30. Subscription Publisher Subscriber onNext 2
  31. Subscription Publisher Subscriber 2
  32. Subscription Publisher Subscriber onComplete 2
  33. Publisher Subscribersubscribe onSubscribe Subscription request onNext onComplete onError
  34. Hot & Cold Cold Hot Passive Active Publish when subscribed Publish regardless Queue Mouse Movement
  35. Operators • map, flatMap, take, subscribe, … • No Operators in Reactive Streams • Left to implementations
  36. Reactor
  37. Project Reactor • Stream extends Publisher • Wrap Publisher
  38. Reactor Streams.just('a' 'b' 'c') .take(2) .map(Character::toUpperCase) .consume(System.out::println);
  39. RxJava
  40. RxJava • Based On Reactive Extensions • Ported to many languages • Rx.NET, RxJava, RxJS, ... • Native support for Reactive Streams coming in 2.x
  41. RxJava Observable.just('a', 'b', 'c') .take(2) .map(Character::toUpperCase) .subscribe(System.out::println)
  42. RxNetty • RxJava on top of Netty • Client/server for TCP and HTTP • Backpressure support
  43. Spring 5
  44. Spring Reactive • Experimental work for Spring 5 • Non-blocking runtimes: • Netty, Jetty,Tomcat, (Undertow) • RxJava, Reactor https://github.com/spring-projects/spring-reactive
  45. public interface ServerHttpRequest { HttpMethod getMethod(); URI getURI(); InputStream getBody(); } public interface ServerHttpResponse { void setStatusCode(HttpStatus status); OutputStream getBody(); } HttpMessage
  46. public interface ReactiveServerHttpRequest { HttpMethod getMethod(); URI getURI(); Publisher<ByteBuffer> getBody(); } public interface ServerHttpResponse { void setStatusCode(HttpStatus status); Publisher<void> setBody(Publisher<ByteBuffer> body); } Reactive HttpMessage
  47. Reactive Wep App Web Service Data
  48. Wanted: Reactiveness • JDBC • MySQL • Postgres • NoSQL • MongoDB • HTTP Client • OkHttp • Spring 5 • …
  49. Reactor @RequestMapping("/capitalize") @ResponseBody public Stream<Person> capitalize( @RequestBody Stream<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); }
  50. RxJava @RequestMapping("/capitalize") @ResponseBody public Observable<Person> capitalize( @RequestBody Observable<Person> persons) { return persons.map(person -> { person.setName(person.getName().toUpperCase()); return person; }); }
  51. More Spring! Spring Meetup http://www.meetup.com/Dutch-Spring- Meetup/ Spring Track GOTO Amsterdam 2016 http://gotoams.com
  52. Q & A https://github.com/spring-projects/spring-reactive
Advertisement