Learning Go, Apache Kafka and Kubernets
Explain how the simulator works and how to run the kafka cluster. Where the kafka is responsible for the data travel between the applications, and the simulator will receive a route through topic new-direction
and send coordinates to the topic new-position
.
Run the Apacha Kafka with the following command:
cd apache-kafka
docker-compose up -d
Enter in the Kafka container and run the producer:
docker exec -it apache-kafka_kafka_1 bash
kafka-console-producer --bootstrap-server=localhost:9092 --topic=route.new-direction
Open another terminal and run the simulator in the main folder:
docker-compose up -d
docker exec -it simulator /bin/bash
go run main.go
With the kafka cluster running, open another terminal and run the consumer:
docker exec -it apache-kafka_kafka_1 bash
kafka-console-consumer --bootstrap-server=localhost:9092 --topic=route.new-position
-
A producer sends a message with the following format to the
route.new-direction
topic:{"clientId": "1", "routeId": "1"}
Where
clientId
is the id of the client that sends the message androuteId
is the id of the route. -
The simulator will read the JSON in the
./destinations/{id}.txt
-
For each coordinate it will send a message with the following format to the
route.new-position
topic:{"clientId": "1", "routeId": "1", "position": [0, 0], "finished": false}
When the "finished" is true it's because the route ends.