Code Monkey home page Code Monkey logo

spring-boot-hikari-connection-pool's Introduction

spring-boot-hikari-connection-pool

Purpose : Use hikari connection pool for db connection object re-use and caching.
Reason : Improve application run-time performance.

Local run steps

1- Start Spring Boot API by running main method containing class CustomerInfoApplication.java in your IDE.
2- Alternatively you can start your Docker container by following the commands below.
NOT : Execute maven command from where the pom.xml is located in the project directory to create Spring Boot executable jar.

 
$ mvn clean install -U -X 

2021-10-12 23:12:25,670 DEBUG [main] com.zaxxer.hikari.HikariConfig: SpringBootJPAHikariCP - configuration:
2021-10-12 23:12:25,699 DEBUG [main] com.zaxxer.hikari.HikariConfig: connectionInitSql..............."select 1"
2021-10-12 23:12:25,700 DEBUG [main] com.zaxxer.hikari.HikariConfig: connectionTestQuery............."select 1"
2021-10-12 23:12:25,700 DEBUG [main] com.zaxxer.hikari.HikariConfig: connectionTimeout...............20000
2021-10-12 23:12:25,701 DEBUG [main] com.zaxxer.hikari.HikariConfig: dataSourceProperties............{password=}
2021-10-12 23:12:25,702 DEBUG [main] com.zaxxer.hikari.HikariConfig: driverClassName................."org.h2.Driver"
2021-10-12 23:12:25,704 DEBUG [main] com.zaxxer.hikari.HikariConfig: isolateInternalQueries..........false
2021-10-12 23:12:25,704 DEBUG [main] com.zaxxer.hikari.HikariConfig: jdbcUrl.........................jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
2021-10-12 23:12:25,705 DEBUG [main] com.zaxxer.hikari.HikariConfig: maxLifetime.....................30000
2021-10-12 23:12:25,705 DEBUG [main] com.zaxxer.hikari.HikariConfig: maximumPoolSize.................10
2021-10-12 23:12:25,708 DEBUG [main] com.zaxxer.hikari.HikariConfig: minimumIdle.....................3
2021-10-12 23:12:25,709 DEBUG [main] com.zaxxer.hikari.HikariConfig: password........................
2021-10-12 23:12:25,713 DEBUG [main] com.zaxxer.hikari.HikariConfig: poolName........................"SpringBootJPAHikariCP"
2021-10-12 23:12:25,714 DEBUG [main] com.zaxxer.hikari.HikariConfig: username........................"sa"
2021-10-12 23:12:25,715 DEBUG [main] com.zaxxer.hikari.HikariConfig: validationTimeout...............250
2021-10-12 23:12:25,715 INFO [main] com.zaxxer.hikari.HikariDataSource: SpringBootJPAHikariCP - Starting...
2021-10-12 23:12:25,989 INFO [main] com.zaxxer.hikari.pool.HikariPool: SpringBootJPAHikariCP - Added connection conn0: url=jdbc:h2:mem:testdb user=SA
2021-10-12 23:12:25,992 INFO [main] com.zaxxer.hikari.HikariDataSource: SpringBootJPAHikariCP - Start completed.
2021-10-12 23:12:26,004 INFO [main] org.springframework.boot.autoconfigure.h2.H2ConsoleAutoConfiguration: H2 console available at '/h2'. Database available at 'jdbc:h2:mem:testdb'

Hikari_Connection_Pool

Tech Stack

Java 11
H2 Database Engine
spring boot
spring boot starter data jpa
spring boot starter web
spring boot starter test
hibernate
logback
maven
springfox-swagger-ui
hikari connection pool
Docker

Docker build run steps

NOT : Execute docker commands from where the DockerFile is located.
NOT : Tested on Windows 10 with Docker Desktop Engine Version : 20.10.8

$ docker system prune -a --volumes 
$ docker build . --tag demo
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
demo latest 9d4a0ec3294e 6 minutes ago 288MB
$ docker run -p 8080:8080 -e "SPRING_PROFILES_ACTIVE=dev" demo:latest

API OPERATIONS

Save a new customer to database

Method : HTTP.POST
URL : localhost:8080/customer-info/customer/save
Request Body :
{
  "name": "name1",
  "age": 1,
  "shippingAddress": {
  "address": {
  "streetName": "software",
  "city": "ankara",
  "country": "TR"
  }
  }
}

Curl Request :

curl --location --request POST 'localhost:8080/customer-info/customer/save' \ 
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "name1",
    "age": 1,
    "shippingAddress": {
        "address": {
            "streetName": "software",
            "city": "ankara",
            "country": "TR"
        }
    }
}'

Response :

HTTP response code 200

{
    "id": 1,
    "name": "name1",
    "age": 1,
    "shippingAddress": {
        "id": 1,
        "address": {
            "id": 1,
            "streetName": "software",
            "city": "ankara",
            "country": "TR"
        }
    }
}

List all customers saved to database

Method : HTTP.GET
URL : localhost:8080/customer-info/customer/list
Request Body :
{}
Curl Request :

curl --location --request GET 'localhost:8080/customer-info/customer/list' \
--header 'Content-Type: application/json' \
--data-raw '{}'

Response :

HTTP response code 200

[
    {
        "id": 1,
        "name": "name1",
        "age": 1,
        "shippingAddress": {
            "id": 1,
            "address": {
                "id": 1,
                "streetName": "software",
                "city": "ankara",
                "country": "TR"
            }
        }
    }
]

spring-boot-hikari-connection-pool's People

Contributors

tufangorel avatar

Watchers

 avatar  avatar

Forkers

123meenakshi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.