Spring Cloud Gateway
Testing spring cloud with integration of, without Netflix dependencies
- Spring Gateway
- Spring Load-balancer
- Spring Webflux (client)
Gateway configuration
Gateway configuration takes these:
API Url | Method | Description | Goal |
---|---|---|---|
/api/v1/{lang} | GET | Greetings response | To test gateway load-balancing and data failure. Include chain filters. |
/api/v1/{lang} | POST | Greetings response, pass parameter "name" | To test gateway load-balancing and data failure. Include chain filters. |
/api/v2/{lang} | GET | Greetings response | Enabling routing via codes. |
/upload | POST | File uploading | File limitation control |
/socket-io/event-emitter | Websocket | Test websocket | Test websocket, use this site "https://www.websocket.org/echo.html" and enter ws://{hostname}:{port} |
/images/* | GET | Routing images to another location | Routing image, redirect |
/static/report/sample.txt or /static/images/pictoral.jpg | GET | Static file access, Add header "Token" = "abc123" to request |
NOTES: Filter enables for ip address
NOTES: Load balancing is using health-check configuration and it's checked every 5seconds. Cached need to be disabled to allow Load balancing.
NOTES: To change path for health-check modify spring.cloud.loadbalancer.health-check.path.default (or remove it)
Test proved
- Load-balancing via health-check, if "spring.cloud.loadbalancer.configurations: health-check" and are based on 5 seconds interval with program path /status as check. If reverting to round-robing, remove "spring.cloud.loadbalancer.configurations" and "spring.cloud.loadbalancer.cache" in application.yml. No Zuul or Ribbon is used in this setting.
- Simple Cloud Discovery instead of using Eureka.
- Web Filtering and ordering in Gateway.
- Traffic-control based on IP headers to deny access.
- Websocket and load-balancing on websocket.
- Resource routing.
- File upload and controlling file limitation access.
- Enabling CORS.
- Disable Dynamic resource control by adding spring.cloud.config.enabled = false in bootstrap.yml
- Serving of static files. (Does not address caching resources, would think running another microservice is better.)
Webclient
Web client is using Webflux and are Docker Compose enabled.
- To run manually, do ./gradlew bootRun
- To run via docker do
./build-docker.sh
docker run -p 8081:8080 demo-gw-web:1.0
docker ps
- If to run via docker -compose, do
#docker-compose build
docker-compose up -d
#docker-compose down
NOTES: Used actuator, where the url http://{hostname}:{port}/actuator/health returns the server status for gateway health check.. There is also http://{hostname}:{port}/status to reply for gateway health check. Remove "path.default" from spring.cloud.loadbalancer.health-check and it will point to /actuator/health.
Load Test and Test Suite
- Download SOAP UI.
- Import project from gw-demo\soapui-test\SOAPProject.xml
- Or use apache load test (without an idea if there are errors)
ab -n 100 -c 10 http://127.0.0.1:9000/api/v1/
Getting Started or Running Program
-
Change directory to /gw-demo/src/main/resources and open application.yml, modify 'spring.cloud.discovery.client.simple.instance.greeting-service(s).uri', and change "raspberrypi" to "localhost" or "127.0.0.1".
-
Start gateway by executing:
cd gw-demo
./gradlew bootRun
-
Try and do a curl GET on http://localhost:9000/api/v1/greetings/pt. It should FAIL
-
Start webservices by either
## Method 1
cd web-demo
./gradlew bootRun
#change web-demo/src/main/resources/application.yml, and change PORT to 8081.
./gradlew bootRun
## Method 2
Run docker, see method above.
## Method 3
Run docker-compose