Skip to content

MaximRom00/Microservices-example

Repository files navigation

Microservices-example

Example of a microservices using Spring Cloud, Spring Boot, Docker, Mysql, MongoDB, RabbitMQ, Keycloak, Spring WebFlux, Resilience4J

About the project

  • User can create, customer, create order and get all orders by customer through API Gateway. MySQL is used for storage customers and orders. The service uses Asynchronous communication between notification service, using RabbitMQ. And WebClient is used as Synchronous communication betwen inventoery service
  • User can create product, get list of all products and check for product availability through API Gateway. MongoDB is used for storage all prodcuts.
  • You can't create order if there isn't your product in warehouse.
  • Notification service is used for getting email after create a new order.
  • User can login through Keycloak
  • All projects configurations: https://github.com/MaximRom00/Microservices-example/tree/master/config-repo

6 services whose name are shown below have been devised in this project:

  • API Gateway - API Gateway which is responsible to route the request to specific microservice. The service does user authentication via OAuth 2.0. You can access the API Gateway at http://localhost:8180.
  • Config Server - Centralized configuration service.
  • Discovery Server - Service registry that allows other services to find and communicate with each other. You can access this service at http://localhost:8761.
  • Customer Service - Responsible for managing orders and customers products.
  • Invtentory Service - Responsible for managing catalog products.
  • Notification Service - Responsible for getting and sending email notification.

Explore Rest APIs

HTTP Verb API Description Request Body Response Body
POST /api/customer Create a new customer CustemerDto Customer
POST /api/order Create a new order OrderDto
GET /api/getOrders Get all orders by customer CustomerDto List of orders
POST /api/product Add a new product to warehouse ProductRequest ProductResponse
GET /api/product Get all products from warehouse None ProductResponse
GET /api/product/inventory Check your product in warehouse String InventoryResponse
POST /api/notification/email Send email NotificationDto None

Used Dependencies

  • Core
    • Spring
      • Spring Boot
      • Spring Security
        • OAuth 2.0 Resource Server
      • Spring Web
      • Spring Data
        • Spring Data JPA
      • Spring WebFlux
      • Spring Cloud
        • Spring Cloud Gateway
        • Spring Cloud Bootstrap
        • Spring Cloud Config Server
        • Spring Cloud Config Client
      • Springdoc-openapi
    • Netflix
      • Eureka Server
      • Eureka Client
  • Database
    • Mysql
    • MongoDB
  • Message Broker
    • RabbitMQ
  • Circuit Breaker
    • Resilience4j
  • Lombok
  • Security
    • Keycloak

Run the App

Maven:

1 ) Start Keycloak and Rabbit through Docker

2 ) Implement their settings

3 ) Download your project from this link: https://github.com/MaximRom00/Microservices-example

4 ) Go to the project's home directory

5 ) Create a jar file though this command: mvn clean install

6 ) Run the project though this command: mvn spring-boot:run

Docker

1 ) Open Docker Desktop or Docker Desktop (if you use Windows 7/8).

2 ) Open terminal and start all containers

    docker-compose up

3 ) Keycloak

    1 ) Open Keycloak on the Browser through localhost:8080 (or http://192.168.99.100:8080 - if you use docker tolbox)
    2 ) Enter username and password (admin : admin)
    3 ) After you login, you need to setup a Realm and Client (https://www.keycloak.org/docs/latest/server_admin/index.html#admin-console)

4 ) RabbitMQ

    1 ) Open Rabbitmq on the Browser through http://localhost:15672 (or http://192.168.99.100:15672 - if you use docker tolbox)
    2 ) Enter username and password (user : password)

5 ) Stops containers

    docker-compose down