fcv / r2dbc-poc

Mirrors https://gitlab.com/fcv/r2dbc-poc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring Boot + R2DBC PoC project

Simple "Proof of Concept" project used to experiment using R2DBC on PostgreSQL along with Spring WebFlux.

Running it

This project has been developed using Maven and Spring Boot and can be executed using:

./mvnw spring-boot:run

It requires a PostgreSQL. A docker-compose.yml is provided so one can run a PostgreSQL instance in a Docker container executing, for example:

docker-compose up --remove-orphans --force-recreate --build

Database's schema is automatically generated by Liquibase during application startup.

Using it

Once it is up and running a Person record can be created using REST API, as for example, using HTTPie:

$ http :8080/persons name="John Doo" birthday=1980-05-29
HTTP/1.1 200 OK
Content-Length: 50
Content-Type: application/json;charset=UTF-8

{
    "birthday": "1980-05-29",
    "id": 4,
    "name": "John Doo"
}

And then listing:

$ http :8080/persons
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
transfer-encoding: chunked

[
    {
        "birthday": "1980-05-29",
        "id": 4,
        "name": "John Doo#4"
    },
    {
        "birthday": "1984-11-01",
        "id": 5,
        "name": "Foo Bar#5"
    }
]

A long lasting SQL query can be simulated by using delay query parameter in GET /persons endpoint:

$ time http --timeout 1200 :8080/persons?delay=PT10S
HTTP/1.1 200 OK
Content-Type: application/json
transfer-encoding: chunked

[
    {
        "birthday": "1980-05-29", 
        "id": 1, 
        "name": "John Doo#1"
    }
]


real	0m10.267s
user	0m0.235s
sys	0m0.012s

PostgreSQL's pg_sleep function will be used to simulate a long lasting SQL query.

SSE (Server Sent Events / streamed application/stream+json)

$ http -S :8080/greetings
HTTP/1.1 200 OK
Content-Type: application/stream+json;charset=UTF-8
transfer-encoding: chunked

{
    "at": "2019-03-30T10:45:27.129Z", 
    "id": "bbd7e5fe-09b8-473a-9e80-1d5489cdafb5@reactor-http-epoll-8", 
    "source": "reactor-http-epoll-8"
}
{
    "at": "2019-03-30T10:45:28.131Z", 
    "id": "bbd7e5fe-09b8-473a-9e80-1d5489cdafb5@reactor-http-epoll-8", 
    "source": "parallel-2"
}

HTTP2

The application also supports HTTP2 protocol

$ curl --http2 -i http://localhost:8080/persons
HTTP/1.1 101 Switching Protocols
connection: upgrade
upgrade: h2c

HTTP/2 200 
content-type: application/json;charset=UTF-8

[ {
  "id" : 5,
  "name" : "Foo Bar#5",
  "birthday" : "1984-11-01"
}, {
  "id" : 4,
  "name" : "John Doo#4",
  "birthday" : "1980-05-29"
}, {
  "id" : 6,
  "name" : "John Doo#6",
  "birthday" : "1980-05-29"
}, {
  "id" : 7,
  "name" : "John Doo#7",
  "birthday" : "1980-05-29"
} ]

About

Mirrors https://gitlab.com/fcv/r2dbc-poc

License:MIT License


Languages

Language:Java 100.0%