Skip to content

Instantly share code, notes, and snippets.

@jordanst3wart
Last active October 22, 2021 00:32
Show Gist options
  • Save jordanst3wart/eb55193655b12423cb684c89f64ef64a to your computer and use it in GitHub Desktop.
Save jordanst3wart/eb55193655b12423cb684c89f64ef64a to your computer and use it in GitHub Desktop.
Spring Reactive stack notes

Reactive spring notes

  • basically just wrap things in Mono, like Mono.just("someString"), flux is like a stream
  • spring data reactive repositories main concern and still in incuberator, has good support for SQL, and some NoSQL, DynamoDB might be hard at the moment. Is better performing that JDBC (see 3.) it's largely based around R2DBC (see 1.), had issues with h2-console, and schema.sql/data.sql seems to be handled differently
  • can apparently handle 1.5 times the number of requests of Servlet stack (see 2.) with a small server, has lower memory, and cpu footprint
  • JSON isn't really streamed but Flux is useful for that
  • code can look really similar to what you are used to (link code)
  • reactive means basically non-blocking
  • using RouterFunctions routing is an option, but maybe not a good one (https://spring.io/guides/gs/reactive-rest-service/)

References

  1. R2DBC: https://github.com/r2dbc for example is for h2 database: https://github.com/r2dbc/r2dbc-h2
  2. https://medium.com/@the.raj.saxena/springboot-2-performance-servlet-stack-vs-webflux-reactive-stack-528ad5e9dadc
  3. R2DBC performance seems fine with a connect pool: https://technology.amis.nl/software-development/performance-and-tuning/performance-of-relational-database-drivers-r2dbc-vs-jdbc/ https://technology.amis.nl/software-development/performance-and-tuning/spring-blocking-vs-non-blocking-r2dbc-vs-jdbc-and-webflux-vs-web-mvc/

Should configure a connection pool with r2dbc: https://github.com/r2dbc/r2dbc-pool/blob/b16b8aad71bbe78c55943e66278df4758d8cb538/src/main/java/io/r2dbc/pool/ConnectionPool.java https://github.com/r2dbc/r2dbc-pool/tree/b16b8aad71bbe78c55943e66278df4758d8cb538

@jordanst3wart
Copy link
Author

Notes:

  • Feign client might not be supported with reactive
  • swagger might not be supported with reactive

@jordanst3wart
Copy link
Author

https://spring.io/reactive is a useful link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment