Giter Site home page Giter Site logo

rate-limit-spring-cloud-gateway's Introduction

README

This example has been forked from Haybu/blog-spring-cloud-gateway. This fork adds two branches:

  • redis

  • custom-limiter

The example consists of three parts: frontend, backend, and gateway. The frontend runs on port 8080 and calls the frontend (port 8081) via the gateway (port 9090).

Redis Branch

To build this example:

git checkout redis
mvn package

For the Redis rate limiter to work, you need a running Redis with no password serving on port 6379. The easiest way to do this is to use docker:

docker run --name redis -e ALLOW_EMPTY_PASSWORD=yes -p 6379:6379 bitnami/redis:latest

Run the three components of the example:

java -jar backend-service/target/backend-service-0.0.1-SNAPSHOT.jar
java -jar frontend-service/target/frontend-service-0.0.1-SNAPSHOT.jar
java -jar gateway/target/gateway-0.0.1-SNAPSHOT.jar

You will need a separate terminal to run each command. You could also run them as detached processes, but then you can’t see the logs on the console.

Use a browser to access http://localhost:8080/message to see the application run.

Use the shell script retry.sh to keep calling the endpoint. You will see some responses and some error 500s when the gateway limits the response rate. You can adjust the rate limiting with the parameters ib gateway/src/main/resources/application.yml.

Custom limiter

The custom rate limiter doesn’t include any rate limiting code, but does show you how to plumb your own custom rate limiter in.

To build this example:

git checkout custom-limiter
mvn package

Run the three components of the example:

java -jar backend-service/target/backend-service-0.0.1-SNAPSHOT.jar
java -jar frontend-service/target/frontend-service-0.0.1-SNAPSHOT.jar
java -jar gateway/target/gateway-0.0.1-SNAPSHOT.jar

You will need a separate terminal to run each command. You could also run them as detached processes, but then you can’t see the logs on the console.

Use a browser to access http://localhost:8080/message to see the application run. The logs for the gateway application show that the key resolver and rate limiter code are called each time the gateway is accessed.

rate-limit-spring-cloud-gateway's People

Contributors

pkpivot avatar

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.