This repo is a sample code to show the usage of an API Gateway. The project uses Spring Cloud Gateway as the main API Gateway. In addition, the Gateway integrates with Consul as the Service Discovery. The objective of this project is three folds:
- Utilize an API Gateway
- Configure and utilize Consul as the main discovery service
- Services are referenced by name and not IP/port
There are 3 services created in this sample project:
- gateway: this is the Spring Cloud Gateway
- service1: this is the service that is exposed by the gateway. This service is written using micronaut
- service2: this service is referenced by service1. This service is written using micronaut
- Java 11. The services are set to use java 11
- Docker. Consul is started using docker
First we need to start Consul by running run-consul.sh. This script uses docker to pull the latest consul image and runs it locally. After consul starts, the UI will be available at: http://localhost:8500
After consul starts, the other services can also start up using the following command:
./run-services.sh
Once all the services are started, the Gateway will forward `/api/billing' to service1. Then, service1 will utilize service2 for some of the information.
To stop the services run the following command:
./stop-services.sh