This sample uses Ocelot as an apigateway and load balancer connected with Consul (Service Discovery), balancing requests to a sample web application, which have 3 replica.
The web application registers itself in Consul using its hostname (also could be configured using the container IP). Ocelot reads the available services from Consul to expose the working containers and makes balancing request between these 3 replica.
Run the docker-compose.yml
file in the repository, this will start 5 containers: consul, apigateway and 3 replicas of the sample web application.
docker-compose up -d
Once you can open your browser pointing to the apigateway:
http://localhost:8080
Also for check services in Consul:
http://localhost:8500
Then you can see something similar to this
Consul with all services registered:
Web application replicas with hostname highlighted:
Diferent responses from services through the api gateway: