Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Reactive Programming with Spring WebFlux Worksh...

Reactive Programming with Spring WebFlux Workshop - DevoxxUK 2017

These last few years Reactive Programming has found the hearts of a significant amount of developers. The fact that Spring 5 will incorporate the possibility of programming Reactive Systems in its core framework through the Spring Web Reactive project is a very positive development (pun intended) and shows the paradigm shift towards declarative programming.

This Hands-on Lab starts with the basics of Reactive Programming (in a nutshell) after which we’ll quickly move on to the actual hands-on part of the session. Using a number of small programming assignments we will familiarize you with all the concepts involving Reactive Programming, and the Spring 5 Web Reactive module. Then, with a real-life use case, we will finally show you why it is such a powerful paradigm. So let us introduce you to a way of building applications in a declarative way, as opposed to imperatively, resulting in more responsive and resilient applications.

Bas W. Knopper

May 12, 2017
Tweet

More Decks by Bas W. Knopper

Other Decks in Technology

Transcript

  1. Let’s do this before we start git clone https://bitbucket.org/rlippolis/spring-web-reactive-workshop reactive-spring-intro

    -> mvn clean verify mememon-go-client -> npm install mememon-go-server -> mvn clean verify npm install -g angular-cli
  2. Making the paradigm-shift to Reactive Programming with Spring 5 Web

    Reactive Riccardo Lippolis - JDriven Bas W. Knopper - JCore
  3. Riccardo Lippolis - JDriven Bas W. Knopper - JCore Making

    the paradigm-shift to Reactive Programming with Spring 5 WebFlux
  4. Java 8 Streams vs. Reactive Streams • A Stream is

    pull based • It "asks" for items to process • Iterable++ • A Reactive Stream is push based • You are notified when an element is available
  5. Reactor • Made by Pivotal! (Spring FTW \0/) • A

    foundation for asynchronous applications on the JVM • Based on the Reactive Streams Specification (same concepts, different naming) • Latest: 3.0.7.RELEASE
  6. Examples - Creating Reactive Streams • Arbitrary number of items:

    Flux<String> flux = Flux. just("Hello", "World!"); • Converting an existing collection: List<Integer> list = Arrays. asList(1, 3, 5); Flux<Integer> flux = Flux. fromIterable(list); • Empty stream: Flux.empty();
  7. Examples - Manipulating Streams • Filtering Flux.just(1, 2, 3, 4,

    5) .filter(n -> n % 2 == 0) .subscribe(System.out::println); // [2, 4] • Transforming Flux.just(1, 2, 3, 4, 5) .map(i -> i * 2) .subscribe(System.out::println); // [2, 4, 6, 8, 10]
  8. Spring WebFlux Uses the familiar Spring Web MVC programming model

    (@Controller, etc.)... ...but with a new reactive, non-blocking engine
  9. Current state of implementation • Version: 5.0.0 RC1 (Not production

    ready!) • Focus on REST (Server & Client) • JSON (Jackson) / XML (JAXB) • SSE streaming • Spring Data Kay M1 • Reactive support for MongoDB, Cassandra and Redis
  10. Workshop part 1: Master the koans • Open the reactive-spring-intro

    project • Fix all the tests / koans in: src/test/java/com/jdriven/reactive/exercises
  11. Workshop part 2: Mememon Go • Demo explaining Use case

    • Make all the tests pass by implementing the code • Make the application work :)
  12. What’s next? • Support for Reactive types in other Spring

    projects, e.g.: • Spring Cloud • Spring Security • …? • GA Release • Current release: 5.0.0 RC1 • GA in june/july?