Skip to content

Spring Boot Microservice Example(Eureka Server, Config Server, API Gateway, Services , RabbitMq, Keycloak)

Notifications You must be signed in to change notification settings

dangokuson/SpringBootMicroservices

 
 

Repository files navigation

Spring Boot Microservice Example(Eureka Server, Config Server, API Gateway, Services , RabbitMq, Keycloak)

Main Information

About the project

  • User can register and login through Keycloak
  • User can register and login through Keycloak
  • Admin can create, update, delete advertisement and get advertisement by its is and get all advertisements from management service to advertisement service through API Gateway
  • Admin can approve and reject advertisement from advertisement service to report service by using managment service through API Gateway
  • User canget advertisement by its is and get all advertisements from management service to advertisement service through API Gateway
  • The view count of the approved advertisement are increasing when user try to show it

7 services whose name are shown below have been devised within the scope of this project.

  • Config Server
  • Eureka Server
  • API Gateway
  • User Service
  • Management Service
  • Advertisement Service
  • Report Service

🔨 Run the App

Docker

1 ) Install Docker Desktop. Here is the installation link : https://docs.docker.com/docker-for-windows/install/

2 ) Open Terminal under resources folder to run Keycloak and RabbitMq on Docker Container

    docker-compose up -d

3 ) Implement Keycloak Settings

    1 ) Open Keycloak on the Browser through localhost:8181
    2 ) Enter username and password (admin : admin)
    3 ) Create Client named for spring-boot-microservice-keycloak and define it in Keycloak config of user service
    4 ) Change client's access type from public to confidential
    5 ) Get secret key to define clientSecret in Keycloak config of user service
    6 ) Define roles for Admin and User as ROLE_ADMIN and ROLE_USER

4 ) Implement Rabbitmq Settings

    1 ) Open Rabbitmq on the Browser through http://localhost:15672
    2 ) Enter username and password (rabbitmq : 123456)
    3 ) Open Admin section in the navbar
    4 ) Define new user named guest and its username , password (guest : guest , role : administrator) , next give all permissiion (Virtual host : "/" , regexp : ".*")

Maven>

1 ) Start Keycloak and Rabbit through Docker

2 ) Implement their settings

3 ) Download your project from this link https://github.com/Rapter1990/SpringBootMicroservices

4 ) Go to the project's home directory : cd SpringBootMicroservices

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

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

To execute the API's through the gateway

1) http://localhost:8600/api/v1/users/signup
2) http://localhost:8600/api/v1/users/login
3) http://localhost:8600/api/v1/users/info 
4) http://localhost:8600/api/v1/management/admin_role/create/{user_id} 
5) http://localhost:8600/api/v1/management/admin_role/alladvertisements
6) http://localhost:8600/api/v1/management/admin_role/alladvertisements/{advertisement_id} 
7) http://localhost:8600/api/v1/management/admin_role/update/{advertisement_id}
8) http://localhost:8600/api/v1/management/admin_role/delete/{advertisement_id} 
9) http://localhost:8600/api/v1/management/admin_role/advertisement/{advertisement_id}/approve
10) http://localhost:8600/api/v1/management/admin_role/advertisement/{advertisement_id}/reject
11) http://localhost:8600/api/v1/management/user_role/alladvertisements
12) http://localhost:8600/api/v1/management/user_role/advertisement/{advertisement_id} 

Explore Rest APIs

Method Url Description Valid Request Body Valid Request Params Valid Request Params and Body No Request or Params
POST signup Sign Up for User and Admin Info
POST login Login Info
GET info Get User's Role Information (ROLE_USER or ROLE_ADMIN) Info
POST create/{user_id} Create Advertisement for User Info
GET alladvertisements Get all advertisements From Admin Info
GET alladvertisements/{advertisement_id} Get advertisement by Id From Admin Info
PUT update/{advertisement_id} Update advertisement by Id Info
DELETE delete/{advertisement_id} Delete advertisement by Id Info
GET advertisement/{advertisement_id}/approve Approve advertisement By Id Info
GET advertisement/{advertisement_id}/reject Reject advertisement By Id Info
GET alladvertisements Get all advertisements From User Info
GET alladvertisements alladvertisements/{advertisement_id} Info

Used Dependencies

  • Core
    • Spring
      • Spring Boot
      • Spring Security
      • Spring Web
        • RestTemplate
      • Spring Data
        • Spring Data JPA
      • Spring Cloud
        • Spring Cloud Gateway Server
        • Spring Cloud Config Server
        • Spring Cloud Config Client
    • Netflix
      • Eureka Server
      • Eureka Client
  • Database
    • Mysql
  • Message Broker
    • RabbitMQ
  • Security
    • Keycloak Server
    • Keycloak OAuth2
    • Keycloak REST API

Valid Request Body

    http://localhost:8600/api/v1/users/signup

    {
        "username" : "springbootmicroserviceuser",
        "password" : "user123456",
        "name" : "Micro User",
        "surname" : "User Surname",
        "phoneNumber" : "123456789",
        "email" : "[email protected]",
        "role" : "ROLE_USER"
    }

    http://localhost:8600/api/v1/users/signup

    {
        "username" : "springbootmicroserviceadmin",
        "password" : "admin123456",
        "name" : "Micro Admin",
        "surname" : "Admin Surname",
        "phoneNumber" : "123456789",
        "email" : "[email protected]",
        "role" : "ROLE_ADMIN"
    }
    http://localhost:8600/api/v1/users/login
    Bearer Token : Access Token of User from Keycloak
    {
        "username" : "springbootmicroserviceuser",
        "password" : "user123456"
    }

    http://localhost:8600/api/v1/users/login
    Bearer Token : Access Token of Admin from Keycloak
    {
        "username" : "springbootmicroserviceadmin",
        "password" : "admin123456"
    }

Valid Request Params

    http://localhost:8600/api/v1/management/admin_role/alladvertisements/{advertisement_id} 
    Bearer Token : Access Token of Admin from Keycloak
    http://localhost:8600/api/v1/management/admin_role/delete/{advertisement_id} 
    Bearer Token : Access Token of Admin from Keycloak
    http://localhost:8600/api/v1/management/admin_role/advertisement/{advertisement_id}/approve
    Bearer Token : Access Token of Admin from Keycloak
    http://localhost:8600/api/v1/management/admin_role/advertisement/{advertisement_id}/reject
    Bearer Token : Access Token of Admin from Keycloak
    http://localhost:8600/api/v1/management/user_role/alladvertisements/{advertisement_id} 
    Bearer Token : Access Token of Admin from Keycloak

Valid Request Params and Body

    http://localhost:8600/api/v1/management/admin_role/create/{user_id} 
    Bearer Token : Access Token from Keycloak
    {
        "title" : "Advertisement 1 for User 1",
        "price" : 200
    }
    http://localhost:8600/api/v1/management/admin_role/update/{advertisement_id}
    Bearer Token : Access Token from Keycloak 
    {
        "title" : "Advertisement 1 for User 1 Updated",
        "price" : 300
    }

No Request or Params

    http://localhost:8600/api/v1/users/info
    Bearer Token : Access Token of Admin or User from Keycloak 
    http://localhost:8600/api/v1/management/admin_role/alladvertisements
    Bearer Token : Access Token of Admin from Keycloak 
    http://localhost:8600/api/v1/management/user_role/alladvertisements
    Bearer Token : Access Token of User from Keycloak 

Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

About

Spring Boot Microservice Example(Eureka Server, Config Server, API Gateway, Services , RabbitMq, Keycloak)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 97.3%
  • Dockerfile 2.7%