Skip to content

OmarEhab007/Microservice-SpringBoot

Repository files navigation

Microservices Demo

A demonstration of a microservices architecture using Spring Boot, gRPC, Kafka, and monitoring with Prometheus and Grafana.

Architecture Overview

This project implements a microservices architecture with the following components:

  • REST Service: Provides RESTful API endpoints for product management
  • gRPC Service: Provides gRPC endpoints for internal service communication
  • Kafka: Message broker for event-driven communication between services
  • Prometheus: Metrics collection and monitoring
  • Grafana: Visualization of metrics and dashboards

The application uses the Outbox Pattern for reliable event publishing and follows domain-driven design principles.

Technologies Used

  • Java 17
  • Spring Boot 3.2.3
  • Spring Data JPA
  • gRPC
  • Apache Kafka
  • H2 Database
  • Prometheus
  • Grafana
  • Docker & Docker Compose
  • Maven
  • Lombok
  • OpenTelemetry

Project Structure

The project is organized into multiple modules:

  • common: Shared code, models, and utilities
  • rest-service: RESTful API service for product management
  • grpc-service: gRPC service for internal communication
  • docker: Docker configuration files

Getting Started

Prerequisites

  • Java 17 or higher
  • Maven 3.6 or higher
  • Docker and Docker Compose

Running the Application

  1. Clone the repository:

    git clone https://github.com/yourusername/microservices-demo.git
    cd microservices-demo
  2. Build the application:

    mvn clean package -DskipTests
  3. Start the services using Docker Compose:

    docker-compose up -d
  4. The following services will be available:

API Endpoints

Products API

  • GET /api/products: Get all products
  • GET /api/products/{id}: Get a product by ID
  • POST /api/products: Create a new product
  • PUT /api/products/{id}: Update a product
  • DELETE /api/products/{id}: Delete a product

Monitoring

The application includes comprehensive monitoring with Prometheus and Grafana.

Metrics

  • JVM metrics (memory, GC, threads)
  • HTTP request metrics
  • Database connection metrics
  • Kafka metrics
  • Custom business metrics

Dashboards

You can set up Grafana dashboards for:

  • System monitoring
  • Application performance
  • Business metrics

Event-Driven Architecture

The application uses an event-driven architecture with Kafka:

  1. REST service creates/updates/deletes products
  2. Events are published to Kafka using the Outbox pattern
  3. gRPC service consumes events and processes them

Development

Adding New Features

  1. Implement the feature in the appropriate service
  2. Add tests
  3. Update documentation
  4. Submit a pull request

Running Tests

mvn test

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Spring Boot team for the excellent framework
  • The open-source community for all the tools and libraries used in this project

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors