Giter Site home page Giter Site logo

m-thirumal / spring-cloud-gateway Goto Github PK

View Code? Open in Web Editor NEW
13.0 3.0 1.0 1.09 MB

Spring cloud gateway with Rate Limiter (Redis) [Service denial], Circuit Breaker (Resilience4J), Load balancing, encryption and decryption, etc.

Java 100.00%
springcloudgateway springboot2 resilience4j rate-limiter circuit-breaker throttling api-throttling router loadbalancing microservice

spring-cloud-gateway's Introduction

spring-cloud-gateway

Gateway

Features:

  • Rate Limiter
  • Circuit Breaker
  • Encryption and Decryption of request and response body
  • Google Re-Captcha validation at gateway for all microservices
  • TLS/SSL

Prerequisite - To Run the following projects to get the proper result

  1. Eureka Server
  2. Eureka Client 1 / MicroServices 1
  3. Eureka Client 2 / MicroServices 2
  4. Redis

To Create jar

mvn clean package -DskipTests=true

Run as jar from terminal

java -jar target/spring-cloud-gateway-0.0.1-SNAPSHOT.jar

Routing and Load balancer

Gateway Architecture

Encryption & Decryption

Encryption of request body and response body is implemented in global filter and in route 2.

f.filter(encryptDecryptFilter.apply(new EncryptDecryptFilter.Config()))

Rate Limiter

i.e Service Denial

SCG

Redis is used for rate limiter, which is used for protecting application from API throttling (Service Denial)

Rate Limiter

Circuit Breaker

Circuit Breaker has three states Closed State, Open State, Half Open State. The image below shows how the flow from one state to another changes.

  1. The Circuit Breaker will be in the Closed state when everything is running as expected when failure starts coming it waits until the set threshold limit is reached then goes to Open state.

  2. While in Open states no calls will be going to failing remote service until certain wait time, then it goes to Half-Open state, in this stage reduced amount of calls goes to remote service to make sure the calls are successful, IF the calls are responding as expected it will go to Closed state or it goes back to Open state avoiding calls to failing remote service.

Circuit-Breaker

Google Recaptcha

Google Recaptcha can be verified at gateway instead of verifying it in each microservices. Avoid code duplication

TLS/SSL

To Enable SSL, add the following properties in the yml file and add the certificate in .p12 format

server:
  port: 9095
  ssl: 
    enabled: true
    key-store: classpath:keystore.p12
    key-store-password: thirumal
    key-store-type: PKCS12
    key-alias: gateway
  compression:
    enabled: true

Get free SSL certificate from Let's Encrypt

To Generate the .p12 from .pem use the following commands

openssl pkcs12 -export -in fullchain1.pem -inkey privkey1.pem -out keystore.p12 -name gateway -CAfile chain1.pem -caname root

spring-cloud-gateway's People

Contributors

m-thirumal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

bellmit

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.