Simple example of using Kafka from rust.
Code from: [https://blog.logrocket.com/building-rust-microservices-apache-kafka/#getting-started-kafka]
- Run local docker kafka server. See "Docker kafka" below to run and create initial topic
- cargo run
- producer sends 10 new events (data) to kafka
- consumer retrieves all events for the topic.
- Ctrl-c to end, and run again to see consumer grow.
docker run --rm -p 2181:2181 -p 9092:9092 --name kafka-docker-container --env ADVERTISED_HOST=127.0.0.1 --env ADVERTISED_PORT=9092 spotify/kafka
Inside container
/opt/kafka*/bin/kafka-topics.sh --topic topic-name --create --zookeeper localhost:2181 --partitions 1 --replication-factor 1