Skip to content

API Gateway Service with Netflix Zuul and Spring Cloud Gateway

Notifications You must be signed in to change notification settings

musabbozkurt/api-gateway-service

Repository files navigation

Table of Contents

  1. Summary
  2. Getting Started
  3. Contributing
  4. Contact
  5. References

Summary

api-gateway-service project established by combination of the following services and features.

Services

 * api-gateway
 * payment-service
 * student-service
 * swagger2-application
 * openai-service

Features

 * Zuul Api Gateway
 * Springfox Swagger2
 * Event Driven Architecture with RabbitMQ
 * Sleuth and Zipkin dependencies to track the logs
 * Postman collection to test by using Postman
 * Keycloak integration is completed under the payment-service
 * Feign Client secure call with Keycloak integration is completed under the student-service
 * MDC was added to improve logging between microservices
 * Google reCAPTCHA was added to secure endpoint calls
 * HCaptcha repo migration is completed under the student-service
 * openai-service repo migration is completed

Getting Started

To get a local copy up and running please follow these simple steps.

Prerequisites

Followings should be installed and links for how to install them.

  • Java 17 or higher How to install Java

  • Maven How to install Maven

  • Lombok How to install Lombok

  • Docker How to install Docker

    * Java 17 or higher version should be installed on your machine -> export JAVA_HOME=$(/usr/libexec/java_home -v 17)
    * Install Apache Maven 
    
    * Docker installation 
        * Please use the following link to install docker on your machine -> https://docs.docker.com/get-docker/
        * Run the following command command in the docker-compose.yml directory 
            to install RabbitMQ, PostgreSQL and Keycloak -> docker-compose up -d
        * After docker images are installed, run the following command on terminal or cmd 
          to create a Keycloak initial admin user.
          
           * docker exec local_keycloak \
                 /opt/jboss/keycloak/bin/add-user-keycloak.sh \
                 -u admin \
                 -p admin \
             && docker restart local_keycloak 
             
        * Log in to http://localhost:28080/auth/ with username: admin and password: admin
    
    **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** 
    **** If you want to ignore Google reCAPTCHA, remove @RequiresCaptcha from api-gateway/src/main/java/com/mb/apigateway/filter/PreFilter.java ****
    ****                               Don't need to do the steps under -> Google reCAPTCHA installation                                        ****
    **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** 
      
    * Google reCAPTCHA installation
        * Log in to the following url -> https://www.google.com/recaptcha/admin/create
        * Fill the necessary fields. 
            * This url can guide you -> https://examples.javacodegeeks.com/wp-content/uploads/2020/12/springboot-google-captcha-google-config-img1.jpg 
        * Copy SITE KEY and SECRET KEY and add them into related fields that are in the api-gateway/src/main/resources/application.yml file
        * HCaptcha integration was implemented in 4 different ways in com/mb/studentservice/api/controller/HCaptchaController.java (OPTIONAL)
    
    * Postman can be installed (OPTIONAL) -> https://www.postman.com/downloads/
        * If Postman is installed, import files that are under the postman_collection folder
        * How to import postman collection -> https://learning.postman.com/docs/getting-started/importing-and-exporting-data/#importing-postman-data
    
    * Run the following command before running payment-service -> mvn clean install or mvn clean package
    * Run the following command in each service directory to run Spring Boot Applications -> mvn spring-boot:run
    
    * Create new secret key and replace all YOUR_API_KEY_HERE in code with this new key -> https://platform.openai.com/account/api-keys
    

Installation

  1. Clone the repo

     git clone https://github.com/musabbozkurt/api-gateway-service.git
  2. Run Spring Boot applications

    1. mvn clean install or mvn clean package
    2. mvn spring-boot:run
  3. Additional information to access endpoints, swagger and actuator

  4. How to run in Docker

     1 - Open Docker Quickstart Terminal
     2 - Go to the project directory from Docker Quickstart Terminal
     3 - Create Docker image by typing the following command -> docker build -t api-gateway-service-project.jar
     4 - Type the following command to make sure docker image has been created -> docker image ls
     5 - Type the following command to run docker image -> docker run -p 9090:8080 api-gateway-service-project.jar

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/amazing-feature)
  3. Commit your Changes (git commit -m 'Add some amazing features')
  4. Push to the Branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Contact

References