Successfully reported this slideshow.
Your SlideShare is downloading. ×

Social connections14: Super charge your API’s with Reactive streams

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Loading in …3
×

Check these out next

1 of 43 Ad
Advertisement

More Related Content

Slideshows for you (20)

Similar to Social connections14: Super charge your API’s with Reactive streams (20)

Advertisement

More from Frank van der Linden (20)

Recently uploaded (20)

Advertisement

Social connections14: Super charge your API’s with Reactive streams

  1. 1. Berlin, October 16-17 2018 Super charge your API’s with Reactive streams Frank van der Linden Full stack Developer elstar IT
  2. 2. Social Connections 14 Berlin, October 16-17 2018 Me • Freelance Full stack Java developer • Owner of elstar IT • Curious of new technology • IBM Champion
  3. 3. Social Connections 14 Berlin, October 16-17 2018 How to proceed •Introduction of Reactive programming •Spring Boot and Webflux •Build your first reactive API •Demo and coding
  4. 4. Social Connections 14 Berlin, October 16-17 2018 Introduction of Reactive programming
  5. 5. Social Connections 14 Berlin, October 16-17 2018 Reactive programming is programming with asynchronous data streams.
  6. 6. Social Connections 14 Berlin, October 16-17 2018 Blocking API calls
  7. 7. Social Connections 14 Berlin, October 16-17 2018 Blocking API calls • Limited amount of requests • Could cause wait time • Useful for request dependencies
  8. 8. Social Connections 14 Berlin, October 16-17 2018 Non-Blocking API calls
  9. 9. Social Connections 14 Berlin, October 16-17 2018 Non-Blocking API calls • (Almost) no limited requests • Can process multiple requests • Not knowing when response are returned • Modern javascript frameworks rely on. (Angular, React, VueJS)
  10. 10. Social Connections 14 Berlin, October 16-17 2018 Reactive manifesto
  11. 11. Social Connections 14 Berlin, October 16-17 2018 Reactive manifesto • Responsive: a reactive system needs to handle requests in a reasonable time • Resilient: a reactive system must stay responsive in the face of failures • Elastic: a reactive system must stay responsive under various loads • Message driven: components from reactive systems interacts using asynchronous message passing
  12. 12. Social Connections 14 Berlin, October 16-17 2018 Publish/Subscribe principle • Loose coupling • Scalability • Non-blocking
  13. 13. Social Connections 14 Berlin, October 16-17 2018 Reactive frameworks • Node.js • RxJava and RxJS • Webflux • Lightbend (Akka) • Vertx
  14. 14. Social Connections 14 Berlin, October 16-17 2018 Spring Boot and Webflux
  15. 15. Social Connections 14 Berlin, October 16-17 2018 First things first
  16. 16. Social Connections 14 Berlin, October 16-17 2018 Spring boot • Open Source, coordinated by Pivotal • Java based applications • Auto configure as much as possible • Built in metrics and health checks • Very good documentation
  17. 17. Social Connections 14 Berlin, October 16-17 2018 Spring boot - component scan • @Service, @Controller, @Repository and more @Components will be scanned • @Autowired will glue everything together
  18. 18. Social Connections 14 Berlin, October 16-17 2018 Spring boot - runs everywhere • Embedded Tomcat makes it just run • Runs on Docker • Runs on Cloud Foundry, like IBM and PCF • Tomcat can excluded, then it runs on Websphere, Tomcat or WildFly • Even on Domino, http://hasselba.ch/blog/? p=2589
  19. 19. Social Connections 14 Berlin, October 16-17 2018 Spring Webflux
  20. 20. Social Connections 14 Berlin, October 16-17 2018 Spring Webflux • Part of the Spring Framework • Available since Spring 5.0 • Uses Netty as webserver instead of Tomcat • Uses the Reactor project under the hood
  21. 21. Social Connections 14 Berlin, October 16-17 2018 Spring Webflux - important objects • Mono, returns 0 or 1 object • Flux, returns 0 or N objects • WebClient, reactive version of http client
  22. 22. Social Connections 14 Berlin, October 16-17 2018 Spring Webflux - Mono example
  23. 23. Social Connections 14 Berlin, October 16-17 2018 Spring Webflux - Flux example
  24. 24. Social Connections 14 Berlin, October 16-17 2018 Spring Webflux - WebClient example
  25. 25. Social Connections 14 Berlin, October 16-17 2018 Build your first reactive API
  26. 26. Social Connections 14 Berlin, October 16-17 2018 Start your first reactive API • Install Maven or Gradle • Move to start.spring.io • Fill in all the fields and select the dependencies • Generate, download and open project in IDE • Run ‘mvn clean install’ for all the dependencies • Start coding • Run application via ‘mvn spring-boot:run’
  27. 27. Social Connections 14 Berlin, October 16-17 2018 Spring Initializr
  28. 28. Social Connections 14 Berlin, October 16-17 2018 Project structure • application.yaml => properties • pom.xml => dependencies
  29. 29. Social Connections 14 Berlin, October 16-17 2018 Application properties • port: on which the service is available • profiles: dev or prod • can used in Java classes • can also moved outside the application
  30. 30. Social Connections 14 Berlin, October 16-17 2018 Repository • Connect to MongoDb • Auto config via property • spring.data.mongodb.uri
  31. 31. Social Connections 14 Berlin, October 16-17 2018 Controller • GET • POST • DELETE • PATCH
  32. 32. Social Connections 14 Berlin, October 16-17 2018 Service • Uses WebClient • Connect to other API’s
  33. 33. Social Connections 14 Berlin, October 16-17 2018 Secure the API
  34. 34. Social Connections 14 Berlin, October 16-17 2018 Swagger the API
  35. 35. Social Connections 14 Berlin, October 16-17 2018 Router • NEW RouterFunction • Can replace the Controller • Uses a Handler class to get the data (Common scenario)
  36. 36. Social Connections 14 Berlin, October 16-17 2018 Demo Application
  37. 37. Social Connections 14 Berlin, October 16-17 2018
  38. 38. Social Connections 14 Berlin, October 16-17 2018 Demo application • Spring boot • Spring Webflux • MongoDb • Angular 6 https://bitbucket.org/flinden68/reactive-streams-starter/src/develop/
  39. 39. Social Connections 14 Berlin, October 16-17 2018 ‘Live coding’: Add new functionality step by step • Backend • Model: Suggestion • Repository, to connect to MongoDb • Controller, the endpoints • Test via Swagger (http://localhost:10000/swagger-ui.html) • Frontend • Model: Suggestion • Service: GET, POST and DELETE • Component: Add new methods • HTML: Add suggestion tab • Check in browser: ng serve (http://localhost:4200/index.html) • Bonus • Handler: Support the suggestions routes • Router: Move all the routes to 1 class to handle all the route requests • Test via Postman
  40. 40. Social Connections 14 Berlin, October 16-17 2018 Questions Asynchronous coordinated lifecycles Chai Stofkoper
  41. 41. Social Connections 14 Berlin, October 16-17 2018 Resources • Spring Initializr • http://start.spring.io/ • Spring Webflux • https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html • Spring Boot • https://projects.spring.io/spring-boot/
  42. 42. Social Connections 14 Berlin, October 16-17 2018 Resources • Maven • https://maven.apache.org/ • Gradle • https://gradle.org/ • Reactive Streams Starter • https://bitbucket.org/flinden68/reactive-streams-starter/src/develop/
  43. 43. Social Connections 14 Berlin, October 16-17 2018 Reach out to me • @flinden68 • http://www.elstarit.nl • flinden68@elstarit.nl • https://nl.linkedin.com/in/flinden68

×