Skip to content

EmilWajda/PostgreSQL-load-balancer-java

Repository files navigation

LoadBalancer Project

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 the loadbalancer-core library to test connections to multiple PostgreSQL databases.

Project Overview

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.


Configuration

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: lbpass

You can adjust the ports or credentials according to your local setup.


Running Databases with Docker

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 -d

This command starts multiple PostgreSQL containers (e.g., lb_db1, lb_db2, lb_db3), each exposing a unique port.

To stop them:

docker compose down

Running the Demo Application

You can run the demo application in two ways:

1. From the console:

./gradlew :demo-app:run

2. From IntelliJ IDEA:

Use the Run Configuration named Main (module demo-app), which executes the pl.edu.agh.Main class.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages