A Microservice demo using:
Spring Boot - The services
Docker - The packaging and deployment
Weave - Multihost Networking and DNS for Docker. The DNS will check health of Services.
VirtualBox (with support for 64bit VM's) for demonstrating multihost.
Software requirements: Vagrant and VirtualBox (relatively new) at least 50 gb free disc space JDK 8 (just for building the artifacts, you can do this in another computer).
git clone https://github.com/Khazrak/WeaveDemo.git
cd WeaveDemo2 Micro Services, Consumer uses Producer.
You Need Java 8 (JDK)
For Linux / OSX
cd weave-demo-consumer
./gradlew build
cd ..
cd weave-demo-producer/
./gradlew build
cd..For Windows:
cd weave-demo-consumer/
gradlew.bat build
cd..
cd weave-demo-producer/
gradlew.bat build
cd..Start the VM's (this will take some time)
vagrant upThe Jars and the Dockerfile will be copied into the VM's
Host 1 (Consumer 1)
vagrant ssh weave-demo-01
cd /home/vagrant/consumer
sudo docker build --rm -t "khazrak/weave-consumer:1.0" .Host 2 (Producer 1)
vagrant ssh weave-demo-02
cd /home/vagrant/producer
sudo docker build --rm -t "khazrak/weave-producer:1.0" .Host 3 (Producer 2)
vagrant ssh weave-demo-03
cd /home/vagrant/producer
sudo docker build --rm -t "khazrak/weave-producer:1.0" .Install Weave on all the VM's
The IP addresses we use for this demo are
172.17.8.101 weave-demo-01
172.17.8.102 weave-demo-02
172.17.8.103 weave-demo-02
Host 1
vagrant ssh weave-demo-01
sudo curl -L git.io/weave -o /usr/local/bin/weave
sudo chmod a+x /usr/local/bin/weaveHost 2
vagrant ssh weave-demo-02
sudo curl -L git.io/weave -o /usr/local/bin/weave
sudo chmod a+x /usr/local/bin/weaveHost 3
vagrant ssh weave-demo-03
sudo curl -L git.io/weave -o /usr/local/bin/weave
sudo chmod a+x /usr/local/bin/weaveOn host weave-demo-01
sudo weave launchOn host weave-demo-02
sudo weave launch 172.17.8.101On host weave-demo-03
sudo weave launch 172.17.8.101On host 1
sudo weave run --with-dns 10.3.1.1/24 -h weave-consumer.weave.local -e SERVICE_NAME="Consumer 1" -p 8080:8080 khazrak/weave-consumer:1.0On host 2
sudo weave run --with-dns 10.3.1.2/24 -h weave-service.weave.local -e SERVICE_NAME="Producer 1" --name="prod1" khazrak/weave-producer:1.0On host 3
sudo weave run --with-dns 10.3.1.3/24 -h weave-service.weave.local -e SERVICE_NAME="Producer 2" --name="prod2" khazrak/weave-producer:1.0On host 1:
curl localhost:8080/rest/getIt will return:
Consumer: Consumer, Producer: Producer XX will be 1 or 2. Usually it will return the same if you try it several times. if you succeed to overload it (to much load) it will use the other.
On host 1:
sudo weave statusAfter using the curl command the weave-status will show the dns-names.
To test the fail over, stop the container that is used, if X is 1 then on host 1 do:
sudo docker stop prod1if X is 2 then on host 2 do:
sudo docker stop prod2Then on host 1:
curl localhost:8080/rest/getThe return message should now show the other number.
On host 1:
sudo weave statusNow one of the dns-names should be gone.
The End
/ Karl Andersson
se.linkedin.com/in/karlandersson1987
If you get:
There are errors in the configuration of this machine. Please fix
the following errors and try again:
File provisioner:
* File upload source file /home/khazrak/Programming/WeaveDemo/weave-demo-consumer/build/libs/weave-demo-consumer-0.0.1-SNAPSHOT.jar must exist
* File upload source file /home/khazrak/Programming/WeaveDemo/weave-demo-producer/build/libs/weave-demo-producer-0.0.1-SNAPSHOT.jar must existThen you haven't done part 1 (or it failed).