Idea of this sample program is to illustrated event driven and non blocking (asynchronous) programming using Vert.x and Spring-boot. This application uses Spring-boot to create standalone http service. POST method is to to create Product, GET method to retrieve Product.
- Spring-boot: Used for creating stand-alone, spring-boot based application
- Vert.x: Used for event-driven (asynchronous) communication between “http-request handler/service” and “db/persistent handler”.
- H2 db (embedded): Used for storing product information.
- Application: This class starts Spring-boot application and also initiates the verticles.
- HttpServerVerticle: This verticle listens to http request, maps route/uri to handler, and forwards requests (non-blocking) to ProductVerticle.
- ProductVerticle: This verticle listens for non-blocking request from "HttpServerVerticle". It creates/fetches Product from db.
- ProductService: This service persists/fetches product information in db (h2 database)
Vertx is used to build the event-driven/non-blocking interaction between components.
- curl -v -X "POST" -H "Content-Type: application/json" -d @test-data1.json http://127.0.0.1:8080/product
- curl -v -X "POST" -H "Content-Type: application/json" -d @test-data2.json http://127.0.0.1:8080/product
- curl -v -X "GET" http://127.0.0.1:8080/product
- curl -v -X "GET" http://127.0.0.1:8080/product/1
- curl -v -X "GET" http://127.0.0.1:8080/product/2