my-spring-boot-experiments
  • README
  • Spring Batch implementation
  • API Example for Archunit
  • spring-boot-chaos-monkey
  • Grafana LGTM Implementation
  • MongoDb for insertion and search using elastic search
  • OpenSearch Implementation
  • spring-boot-rabbitmq-thymeleaf
  • boot-rest-docs-sample
  • boot-strategy-plugin
  • spring-boot-togglz-sample
  • spring-boot-ultimate-redis
  • GraphQL
    • spring-boot-graphql-querydsl
    • GraphQl implementation using webflux
    • GraphQl implementation using webmvc
  • httpClients
    • http-proxy
    • rest-template
    • rest-client
    • web-client-mvc
    • web-client-webflux
  • jmh-benchmark
  • jpa
    • Custom Sequence
    • Hibernate Envers Implementation
    • multiple datasources using Spring Boot
    • spring-boot-hibernate2ndlevelcache-sample
    • JNDI in embedded Tomcat
    • JPA Jooq Marriage
    • JPA locks implementation
    • read-replica-with-spring-boot
    • KeySet Pagination Using Blaze
    • KeySet Pagination Using Data-JPA
    • MultiTenancy using Hibernate in Spring Data JPA
      • multitenancy-db
      • multidatasource-multitenancy
      • Partitioned (Discriminator) Data – the data for each tenant is partitioned by a discriminator value
      • schema
  • open-api-spring-boot
  • r2dbc
    • r2dbc-jooq
    • PostgreSQL JSON and enum column support
    • PostgreSQL Notify and Listen support using reactive spring boot
    • r2dbc-boot
    • reactive-cache
  • scheduler
    • Scheduling using JobRunr
    • Scheduling using Quartz
    • Scheduling using Shedlock distribution
  • Code Of Conduct
Powered by GitBook
On this page
  • Features
  • Prerequisites
  • Getting Started
  • API Endpoints
  • Architecture
  • Running Tests
  • Docker Deployment
  • Monitoring
  • Configuration

Was this helpful?

Edit on GitHub
  1. r2dbc

PostgreSQL JSON and enum column support

This project demonstrates a reactive Spring Boot application using R2DBC with PostgreSQL JSON column support. It implements a blog-like system with posts and comments, featuring pagination and reactive endpoints.


Features

  • Reactive REST API using Spring WebFlux

  • R2DBC with PostgreSQL for reactive database operations

  • JSON column support for flexible data storage

  • Flyway database migrations

  • Pagination and sorting support

  • Docker support with health checks

  • Comprehensive test coverage using TestContainers

  • Metrics and tracing with Micrometer


Prerequisites

  • JDK 21

  • Docker and Docker Compose

  • PostgreSQL 15+


Getting Started

  1. Clone the repository

  2. Run PostgreSQL using Docker:

    docker-compose -f docker/docker-compose.yml up -d
  3. Run the application.

    ./mvnw spring-boot:run

API Endpoints

  • GET /posts?page=0&size=10&sort=title&direction=ASC - Get paginated posts

  • GET /posts/{id} - Get a specific post

  • POST /posts - Create a new post

  • PUT /posts/{id} - Update a post

  • DELETE /posts/{id} - Delete a post

  • GET /posts/{postId}/comments - Get comments for a post

  • POST /posts/{postId}/comments - Add a comment to a post


Architecture

sequenceDiagram
    participant Client
    participant WebRouter
    participant PostHandler
    participant PostRepository
    participant CommentRepository
    participant Database

    Client->>WebRouter: GET /posts?page=0&size=10
    WebRouter->>PostHandler: route to handler
    PostHandler->>PostRepository: findAllWithPagination(offset, size, sort, direction)
    PostRepository->>Database: Execute query
    Database-->>PostRepository: Return posts
    PostHandler->>CommentRepository: findAllByPostIdIn(postIds)
    CommentRepository->>Database: Execute query
    Database-->>CommentRepository: Return comments
    PostHandler->>PostHandler: Combine posts with comments
    PostHandler-->>Client: Return PagedResult<Post>

Running Tests

The project includes both unit and integration tests using TestContainers:

./mvnw verify

Docker Deployment

Build and run the application using Docker:

./mvnw spring-boot:build-image
docker-compose -f docker/docker-compose-app.yml up -d

Monitoring

The application exposes various actuator endpoints for monitoring:

  • Health: /actuator/health

  • Metrics: /actuator/metrics

  • Info: /actuator/info


Configuration

Key application properties can be configured in application.properties:

  • Database connection settings

  • Logging levels

  • Jackson JSON settings

  • Management endpoints

Previousr2dbc-jooqNextPostgreSQL Notify and Listen support using reactive spring boot

Last updated 4 months ago

Was this helpful?