Spring Data Reactive Relational Database Connectivity or R2DBC allows developers to work with SQL databases in a fully-reactive and asynchronous manner, thus moving away from the "one-thread-execution" servlet container model. With the SQL drivers based on the new R2DBC specification from respective vendors, the drivers thus provide a completely new set of APIs to communicate effectively with Relational databases in a non-blocking manner. More details can be found here and here.
This github repository is to document a working code with the minimum required maven dependencies to get a successful 200 GET HTTP Response code. Lest assured, the code is supposed to work with the below mentioned steps.
This code base is based on Spring Data R2DBC with PostgreSQL relational database.
- Connect to PostgreSQL in asynchronous mode from Spring boot
- Validate request and throw custom validation exception
- Handle any exceptions and throws meaningful error messages
- Maintain test classes execution coverage of 85 percentile and above
- Dockerize the app with docker engine installed during image build
- Run
docker run --name my-postgres-db -e POSTGRES_PASSWORD=mypostgrespassword -p 5432:5432 -d postgres:bullseye
. - Connect to database using DBeaver(u: postgres | p: mypostgrespassword)
- Create payroll schema once connected to docker mysql container
- Use payroll schema
- Create customer table.
CREATE TABLE IF NOT EXISTS customers ( cust_id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, country VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
- Create new project.
E.g.spring-postgres-reactive
- Run unit tests & build project :
mvn clean package -T 8
- Build & push docker image to
GitLab :
mvn clean install -T 4 -Dgitlab-image=<<my-gitlab-image>> -Dgitlab-username=<<my-gitlab-username>> -Dgitlab-password=<<my-gitlab-password>>
. my-gitlab-image would look like registry.gitlab.com/ /spring-postgres-reactive/reactive-postgresql: 1.0.1
- Run
docker login registry.gitlab.com -u <<my-gitlab-username>> -p <<my-gitlab-password>>
- Change to above the gitlab image in docker-compose.yml
- Run
docker-compose up
- Import spring-mysql-reactive.postman_collection.json in Postman.
- Hit the APIs.