API Gateway is an edge service that provides a single-entry point for certain groups of microservices.
It acts as unified “front door” to our ecosystem.
Additionally, gateway is integrated with Hystrix for fault tolerance(Circuit Breaker) and Eureka for service discovery.
- Running config-server.
- Running service-registry.
- Running zipkin server.
- Running admin-dashboard.
- Running user-service.
- Running hello-service.
Start application:
./gradlew bootRun
-
Start service.
-
Check available routes in Api Gateway.
-
Check if application successfully registered in service-registry.
-
Check load balancing.
# Hello service curl "http://localhost:8082/api/v1/hello" # Users service curl "http://localhost:8082/api/v1/usersusers" # Hystrix protecting custom route (Example how to use hystrix api in route definition, see RouteConfiguration.java) curl "http://localhost:8082/api/v1/hystrix/hello" # Simulate hystrix failure curl "http://localhost:8082/api/v1/hello/hystrix?shouldFail=true" # Simulate hystrix success curl "http://localhost:8082/api/v1/hello/hystrix?shouldFail=false"
-
Check Hystrix dashboard:
- Go to admin-dashboard.
- Choose 'api-gateway' application.
- Click 'Hystrix' tab and see visualized hystrix stream e.g.
-
Open zipkin ui and investigate traces.
# Clean build jar
./gradlew clean build
# Build docker image
./gradlew jibDockerBuild
Name | Endpoint |
---|---|
Api Gateway |
http://localhost:8082/ |
Api Gateway - available routes |
http://localhost:8082/actuator/gateway/routes |
Api Gateway - Hello service |
http://localhost:8082/api/v1/hello |
Api Gateway - Users service |
http://localhost:8082/api/v1/users |
Api Gateway - Custom route behind hystrix using route definition, see RouteConfiguration.java:22 |
http://localhost:8082/api/v1/hystrix/hello |
Api Gateway - Simulate hystrix error in Hello Service |
http://localhost:8082/api/v1/hello/hystrix?shouldFail=true |
Api Gateway - Simulate hystrix success in Hello Service |
http://localhost:8082/api/v1/hello/hystrix?shouldFail=false |