Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Microservices TP - Spring Boot & Spring Cloud

A complete microservices architecture project using Spring Boot 3.2.0, Spring Cloud 2023.0.0, and Java 17.

📁 Project Structure

microservices-tp/
├── discovery-server/          # Eureka Discovery Server (Port 8761)
├── gateway/                   # Spring Cloud Gateway (Port 8080)
├── user-service/              # User Microservice (Port 8084)
├── product-service/           # Product Microservice (Port 8083)
└── pom.xml                    # Parent POM

🏗️ Architecture

  • Eureka Discovery Server: Service registry for all microservices
  • Spring Cloud Gateway: API Gateway with load balancing
  • User Service: REST API for user management
  • Product Service: REST API for product management

🚀 How to Run

Prerequisites

  • Java 17 or higher
  • Maven 3.6 or higher
  • IDE (IntelliJ IDEA recommended)

Step 1: Build the Project

From the root directory, run:

mvn clean install

Step 2: Start Services (IN THIS ORDER)

1. Start Discovery Server (Eureka)

cd discovery-server
mvn spring-boot:run

Wait until Eureka is fully started, then access: http://localhost:8761

2. Start User Service

Open a new terminal:

cd user-service
mvn spring-boot:run

Service will register with Eureka on port 8084

3. Start Product Service

Open a new terminal:

cd product-service
mvn spring-boot:run

Service will register with Eureka on port 8083

4. Start Gateway

Open a new terminal:

cd gateway
mvn spring-boot:run

Gateway will start on port 8080

Step 3: Verify Services

  1. Check Eureka Dashboard: http://localhost:8761

    • You should see user-service, product-service, and gateway registered
  2. Test Direct Access:

  3. Test via Gateway (Recommended):

📡 API Endpoints

Via Gateway (http://localhost:8080)

User Service

  • GET /users - Get all users
    [
      {"id": "1", "name": "Oussama", "email": "oussama@example.com"},
      {"id": "2", "name": "Yuno", "email": "yuno@example.com"}
    ]
  • GET /users/{id} - Get user by ID
    {"id": "1", "name": "User-1", "email": "user1@example.com"}

Product Service

  • GET /produits - Get all products
    [
      {"id": "p1", "name": "Laptop", "price": "999.99"},
      {"id": "p2", "name": "Phone", "price": "599.99"}
    ]

🛠️ Running in IntelliJ IDEA

  1. Import Project:

    • File → Open → Select microservices-tp folder
    • IntelliJ will detect it as a Maven project
  2. Run Configurations:

    • Create 4 separate Spring Boot run configurations:
      • DiscoveryServerApplication
      • UserServiceApplication
      • ProductServiceApplication
      • GatewayApplication
  3. Start Services:

    • Run them in order: Discovery → User → Product → Gateway

🔧 Technologies Used

  • Spring Boot 3.2.0
  • Spring Cloud 2023.0.0
  • Spring Cloud Netflix Eureka: Service Discovery
  • Spring Cloud Gateway: API Gateway with Load Balancing
  • Java 17
  • Maven: Build Tool

📊 Port Configuration

Service Port
Discovery Server 8761
Gateway 8080
Product Service 8083
User Service 8084

🎯 Key Features

✅ Service Discovery with Eureka
✅ Load Balancing via Spring Cloud Gateway
✅ RESTful APIs
✅ Multi-module Maven project
✅ Production-ready configuration

📝 Notes

  • Always start the Discovery Server (Eureka) first
  • Wait for each service to fully register before starting the next one
  • Check the Eureka dashboard to verify all services are registered
  • Use the Gateway (port 8080) for accessing services in production scenarios

🐛 Troubleshooting

Services not registering with Eureka:

  • Ensure Discovery Server is running first
  • Check application.yml for correct Eureka URL
  • Wait 30-60 seconds for registration to complete

Gateway not routing:

  • Verify all services are registered in Eureka dashboard
  • Check Gateway logs for routing configuration
  • Ensure service names match in Eureka and Gateway routes

Port conflicts:

  • Make sure no other applications are using ports 8080, 8083, 8084, or 8761
  • You can change ports in respective application.yml files

👨‍💻 Author

Essalmani Oussama

Microservices TP Project - Spring Boot 3 & Spring Cloud

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages