badgerwithagun / async-all-the-way-down

Demo of a fully-asynchronous Dropwizard microservice

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Async all the way down

An opinionated, asynchronous, reactive Dropwizard microservice. Uses:

  • Asynchronous JAX-RS server via RX
  • Asynchronous JAX-RS client via RX
  • Chunked responses via RX Flowables
  • Asynchronous Postgres driver

How to try it out

  1. Make sure you have Docker set up and working (it uses TestContainers to start a Postgres instance)
  2. Open in your IDE
  3. Run the DemoTest test to start the server over a temporary database instance
  4. Once the test is up and running, call the following endpoints from your browser:
    1. http://localhost:8081/demo/write to write 100 records to the database, returning them to the browser immediately as they are written
    2. http://localhost:8081/demo/read to read the records back in the same way
    3. http://localhost:8081/demo/readhttp to read the records back via the above endpoint via an HTTP client - again streaming in real time.
    4. http://localhost:8081/demo/count to read the record count
    5. http://localhost:8081/demo/reset to delete the records

Note that responses are streamed back (deliberately slowed down to show chunked responses in progress) and don't block a server thread. The database I/O doesn't block a worker thread either - both use NIO, so you don't need a large thread pool to support high volume.

It's all magic

Check out the JAX-RS Resource - note that all this is achieved largely transparently as long as you write the endpoints using reactive logic.

About

Demo of a fully-asynchronous Dropwizard microservice


Languages

Language:Java 100.0%