-
start docker
-
run this command in 1 terminal
docker run --rm -it \
-p 2181:2181 -p 3030:3030 -p 8081:8081 \
-p 8082:8082 -p 8083:8083 -p 9092:9092 \
-e ADV_HOST=127.0.0.1 \
landoop/fast-data-dev
- because the kafka is long running process, have to keep the terminal opened
- u can go to
127.0.0.1:3030
to see the ui for the virtual machine on browser - open a new terminal and paste
docker run --rm -it --net=host landoop/fast-data-dev bash
kafka-topics --zookeeper 127.0.0.1:2181
press TAB to see what flags are available- To create a topic
kafka-topics --zookeeper 127.0.0.1:2181 --create --topic first_topic --partitions 3 --replication-factor 1
- To list topics
kafka-topics --zookeeper 127.0.0.1:2181 --list
- To describe a topic
kafka-topics --zookeeper 127.0.0.1:2181 --describe --topic first_topic
- To delete a topic
kafka-topics --zookeeper 127.0.0.1:2181 --delete --topic first_topic
kafka-console-producer --broker-list 127.0.0.1:9092 --topic first_topic
then type and hit enter each time- check the ui topics to see the messages
- messages will be randomly assigned to different partitions across topic
- use ctrl+C to end
- must open in yet another terminal because the consumer consumes live so need to send message at same time
kafka-console-consumer
must usebootstrap-server
as optionkafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first_topic
then type and hit enter each timekafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first_topic --from-beginning
to get all historical messageskafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first_topic --from-beginning --partition 0
to get all historical messages from just partition 0- but so far none of the above consumer commands will commit any offsets to the consumer offsets topic
kafka-console-consumer --bootstrap-server 127.0.0.1:9092 --topic first_topic --from-beginning --consumer-property group.id=mygroup1
run once to get all messages but second time u will get nothing because of consumer offsets- use ctrl+C to end