Skip to content

Spring Boot Reactive Relational Database Connectivity(R2DBC) to MySQL

Notifications You must be signed in to change notification settings

vasudeva78/spring-mysql-reactive

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hey there ...

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 MySQL relational database.

Features implemented

  • Connect to MySQL 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
  1. Set up MySQL database

  • Run docker run --name my-sql-db -e MYSQL_ROOT_PASSWORD=mysqlpassword -p 3306:3306 -d mysql:8.0.29-debian.
  • Connect to database using MySQL Workbench(u: root | p: mysqlpassword) -- or -- run mysql command inside the running docker container
  • 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 );
  1. Set up Gitlab for registering the docker image

  • Create new project. E.g.spring-mysql-reactive
  1. Maven commands

  • 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-mysql-reactive/reactive-mysql: 1.0.1
  1. Run the container image pulled from Gitlab

  • 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
  1. Test APIs in Postman

  • Import spring-reactive-urls.json in Postman.
  • Hit the APIs.

Cheers ...