This project consists of two Gradle modules:
loadbalancer-core— the main library responsible for reading database configuration and managing multiple database connections.demo-app— a simple demo application that uses theloadbalancer-corelibrary to test connections to multiple PostgreSQL databases.
The demo application loads a configuration file (config.yml) from its resources directory.
This file contains connection details for multiple PostgreSQL databases (name, URL, username, password).
At runtime, the app uses the ConfigLoader class from the loadbalancer-core module to parse this YAML file and attempt connections to all defined databases.
If everything is configured correctly, the console will display successful connection messages for each database.
The database configuration is located in:
demo-app/src/main/resources/config.yml
Example content:
strategy: round_robin
databases:
- name: db1
url: jdbc:postgresql://localhost:5433/lbdb1
username: lbuser
password: lbpass
- name: db2
url: jdbc:postgresql://localhost:5434/lbdb2
username: lbuser
password: lbpass
- name: db3
url: jdbc:postgresql://localhost:5435/lbdb3
username: lbuser
password: lbpassYou can adjust the ports or credentials according to your local setup.
To run the PostgreSQL databases locally, use the provided docker-compose.yml file in the project root.
You’ll need Docker installed.
docker compose up -dThis command starts multiple PostgreSQL containers (e.g., lb_db1, lb_db2, lb_db3), each exposing a unique port.
To stop them:
docker compose downYou can run the demo application in two ways:
./gradlew :demo-app:runUse the Run Configuration named Main (module demo-app), which executes the pl.edu.agh.Main class.