Steps to run:
- Download Consul Agent and unzip it in a folder.
- Download Consul UI and copy contents to AGENT_PATH/web-ui
- Pull spring-cloud-consul-demo from: https://github.com/seropian/spring-cloud-consul-demo.git
- Run mvn clean package
- Run agent: consul agent from its folder:
consul agent -server -bootstrap-expect 1 -data-dir ./tmp -ui-dir=./web-ui/dist
- Go to spring-cloud-consul-demo folder
- Start 2 instances of service:
java -jar service/target/service-1.0.0.BUILD-SNAPSHOT.jar --server.port=8081
java -jar service/target/service-1.0.0.BUILD-SNAPSHOT.jar --server.port=8082
- Start client instance:
java -jar client/target/client-1.0.0.BUILD-SNAPSHOT.jar --server.port=8080
Done!
Next steps
To see services in consul interface, go to: http://localhost:8500
To see how client app works with services:
- list all services registered with consul (including non-java apps):
localhost:8080/services - list all service instances by service name:
localhost:8080/instances - let the load balancer to select a service instance:
localhost:8080/loadBalancedServiceInstanceon refreshing the page you will see how returned instance is different between calls - call a service by using the java interface:
localhost:8080/helloClient - helloClient it's load balanced by default so on page refresh you shall see response coming from different instances