【消息中心】docker部署kafka

消息中心选择kafka作为消息中间件,docker部署kafka已经比较成熟,所以选择docker快速部署

步骤

拉取镜像

docker pull wurstmeister/kafka docker pull wurstmeister/zookeeper 

启动zookeeper

docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper 

启动kafka 记得修改自己的zookeper ip

 docker run -d --name kafka01 -p 9092:9092 -e KAFKA_BROKER_ID=1 -e KAFKA_ZOOKEEPER_CONNECT=172.20.101.16:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.20.101.16:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -t wurstmeister/kafka 

进入容器

docker exec -it kafka01 bash 

进入kafka安装目录

cd /opt/kafka_2.13-2.8.1/bin/ 

启动生产者

./kafka-console-producer.sh --broker-list localhost:9092 --topic sun 

发送消息

{"datas":[{"channel":"","metric":"temperature","producer":"ijinus","sn":"IJA0101-00002245","time":"1543207156000","value":"80"}],"ver":"1.0"} 

启动消费者

/opt/kafka_2.13-2.8.1/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic sun --from-beginning 

收到消息
在这里插入图片描述
查看版本
docker下首先进行命令行模式

docker exec -it kafka01 /bin/bash 

再次执行下面命令查找kafka的目录

find / -name \*kafka_\* | head -1 | grep -o '\kafka[^\n]*' 

原文链接:https://blog.csdn.net/yujing1314/article/details/122575768?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836884016800178595162%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836884016800178595162&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-20-122575768-null-null.nonecase&utm_term=docker%E9%83%A8%E7%BD%B2

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享