/employee_mgt_system

This is an Employee Management REST Service created using: Spring Webflux Application (Spring Reactive) - Flux vs Mono Spring Data Reactive Mongodb Mongodb Database. It aims inillustrating the reactive programming paradigm.

Primary LanguageJava

Getting Started

This is an Employee Management REST Service created using:

  • Spring Webflux Application (Spring Reactive) - Flux vs Mono
  • Spring Data Reactive Mongodb
  • Mongodb Database

This project implements the following concepts:

Reactive programming is a design paradigm that allows development of event-driven web applications which are responsive and scalable. It is based on Reactive Streams which handles streams of data which are asynchronous.

Why Spring Webflux? Well, reactive programming is achieved in Spring Webflux through the use of Mono and Flux classes which represent a single or multiple values over time respectively.

Reactive programming helps to improve application performance by reducing thread blocking and minimal resource usage. For example:

public Flux<EmployeeDto> findAll() { return employeeRepository .findAll() .map(EmployeeMapper::mapToEmployeeDto) .switchIfEmpty(Flux.empty()); }

This is a sample service method within this project that fetches all employees from our database.Here we are returning a Flux of Employees from Employees repository. This means that the method will stream employees as they become available rather than waiting for all employee data to be loaded before returning them (synchronous).

Run Application

Prerequisite: Ensure you have Mongodb installed on your machine. Can change the database and port details for your Mongodb instance in application.properties file located within the resources folder.

Instructions: Clone this project and run the application either using Eclipse or Intellij, the default port has been set to port 8081

Sample Endpoints:

  1. Searching an employee by Name:

    img.png

  2. Find an employee by their Id:

    img_1.png

Note: For my tests, I have generated test data using Instancio Library as shown below: img_2.png

Reference Documentation

For further reference, please consider the following sections:

Guides

The following guides illustrate how to use some features concretely: