下载适用于Apple M2 Pro的Zookeeper和Kafka Docker镜像
docker pull zookeeper:3.6
docker pull cppla/kafka-docker:arm
下载成功后确认镜像无误
docker images
执行部署命令后查看容器是否启动
docker run -d --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime -e TZ=Asia/Shanghai zookeeper:3.6
docker ps|grep zookeeper
执行Kafka 安装命令
docker run -d --name kafka -v /etc/localtime:/etc/localtime:ro -p 9092:9092 -e TZ=Asia/Shanghai --link zookeeper:zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 --env KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 --env KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 --env KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1 cppla/kafka-docker:arm
查看Kafka容器启动成功
docker ps|grep kafka
进入容器
docker exec -it kafka bash
创建topic
kafka-topics.sh --create --topic topic_create_test --partitions 1 --replication-factor 1 --zookeeper zookeeper:2181
创建一个生产者,并插入数据
bash-4.4# kafka-console-producer.sh --bootstrap-server localhost:9092 --topic topic_create_test
>{"id":773320,"name":"杨娟","address":"吉林省杭州市合川梧州路L座 934689","create_time":1653905861,"event_time":1653905561,"price":40343.9750680629,"list_info":["QeWHWDTPqOyjxivCdHFb","mAEgJHRZnojFWbueQiiR","AZWPwVMRyJKCJMXaEJhp","cbeTljzvygYcDrwdLKel","HFiEKQiFkEejdZQftpbE"],"map_info":{"也是":"aHzrLubeXUZLbwURNwmK","搜索":"MXhrcgUVOmNTqDjIHGTD","一些":"reiKveakVvTvNoesUjYE","女人":"ckoKoxJCrxniQIFAUiZu","之间":"DUXVsnqwtDrnxAcwFcZx"}}
创建一个消费者,往生产者持续插入数据可以看到数据被消费到
bash-4.4# kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic topic_create_test
{"id":773320,"name":"杨娟","address":"吉林省杭州市合川梧州路L座 934689","create_time":1653905861,"event_time":1653905561,"price":40343.9750680629,"list_info":["QeWHWDTPqOyjxivCdHFb","mAEgJHRZnojFWbueQiiR","AZWPwVMRyJKCJMXaEJhp","cbeTljzvygYcDrwdLKel","HFiEKQiFkEejdZQftpbE"],"map_info":{"也是":"aHzrLubeXUZLbwURNwmK","搜索":"MXhrcgUVOmNTqDjIHGTD","一些":"reiKveakVvTvNoesUjYE","女人":"ckoKoxJCrxniQIFAUiZu","之间":"DUXVsnqwtDrnxAcwFcZx"}}