PostgreSQL Notify and Listen support using reactive spring boot
This project demonstrates how to implement PostgreSQL's NOTIFY/LISTEN feature using Spring Boot and R2DBC. It showcases real-time notifications between database and application using PostgreSQL's pub/sub capabilities.
Features
Reactive PostgreSQL connectivity using R2DBC
Implementation of PostgreSQL NOTIFY/LISTEN mechanism
Real-time event notifications
Reactive endpoints for publishing and receiving notifications
Prerequisites
JDK 21
Maven
Docker and Docker Compose
PostgreSQL (or use provided Docker Compose)
Getting Started
Start PostgreSQL using Docker Compose:
Build the application:
Run the application:
Architecture
Usage
To publish a notification:
To subscribe to notifications:
Connect to WebSocket endpoint:
ws://localhost:8080/notifications
Or use Server-Sent Events endpoint:
http://localhost:8080/notifications/sse
Configuration
Key configuration properties in application.properties
:
How It Works
The application establishes a connection to PostgreSQL using R2DBC
It sets up LISTEN on specified channels
When a notification is published:
Application executes NOTIFY command
PostgreSQL broadcasts to all listeners
Listeners receive and process notifications
Connected clients receive notifications via WebSocket/SSE
Contributing
Feel free to submit issues and enhancement requests!
Last updated