Copyright (c) 2019 Johan Vandeweerd
https://github.com/johanvandeweerd/demo
This is a small demo project to play with Spring Boot,
Gradle, Docker and Datadog. It exists of
two microservices: web and worker.
The web service has an HTTP endpoint and puts a message onto a Kafka topic. The worker listens on this topic and prints
the content of the messages to the console.
- Docker
- Docker Compose
- (trail) Datadog account
- Java 11 (optional)
- Replace the value of
DD_API_KEYinops/docker/datadog/docker-compose.ymlwith your (newly created) Datadog API key - Create a docker network named
demo
docker network create demoYou can build the project using a local Java 11 or from Docker.
Execute the following commands from the root of the project to build the demo app and create docker images:
./gradlew dockerTagExecute the following commands from the root of the project to build the demo app and create docker images:
docker build -t demo-build ops/docker/build
docker run -it --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
demo-build ./gradlew dockerTag- Start the datadog agent
(cd ops/docker/datadog ; docker-compose up -d)- Start the kafka broker
(cd ops/docker/kafka ; docker-compose up -d)- Start the demo application
(cd ops/docker/demo ; docker-compose up -d)When running the demo application from an IDE, make sure to
- Add the following to your
/etc/hostsfile
127.0.0.1 kafka datadog- Download the Datadog java agent to the root of the project as
dd-java-agent.jar - Start the
demo-webapp with the following- VM options:
-javaagent:dd-java-agent.jar
- environment variables:
DD_JMXFETCH_ENABLED=trueDD_LOGS_INJECTION=trueDD_SERVICE_NAME=demo-webDD_TRACE_GLOBAL_TAGS=env:demoSERVER_PORT=8000SPRING_PROFILES_ACTIVE=local
- VM options:
- Start the
demo-workerapp with the following- VM options:
-javaagent:dd-java-agent.jar
- environment variables:
DD_JMXFETCH_ENABLED=trueDD_LOGS_INJECTION=trueDD_SERVICE_NAME=demo-workerDD_TRACE_GLOBAL_TAGS=env:demoSPRING_PROFILES_ACTIVE=local
- VM options:
Use your browser or favorite HTTP client to call http://localhost:8080/hello/<your-name> or use the toolbox with the following commands:
cd ops/docker/toolbox
docker build -t toolbox .
docker run -it --rm --network demo toolbox curl http://demo-web:8080/hello/<your-name>
- Tail the logs for the web service
docker-compose logs -f demo_demo-web_1- Tail the logs for the worker service
docker-compose logs -f demo_demo-worker_1- Tail the logs for the datadog agent
docker-compose logs -f datadog_datadog_1- Tail the logs for the kafka broker
docker-compose logs -f kafka_kafka_1- Build the toolbox
cd ops/docker/toolbox
docker build -t toolbox .- Start the toolbox. You can use
ping,dig,netcat,telnet,curlorkafkacat.
Use the following DNS names:- demo-web
- demo-worker
- kafka
- zookeeper
docker run -it --rm --name toolbox --network demo toolbox bash Kill the gradle daemon when you experience the following error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':demo-web:docker'.
> A problem occurred starting process 'command 'docker''