docker-compse 启动文件

version: '3'

name: kafka1

services:
  zookeeper:
    image: bitnami/zookeeper:latest
    ports:
      - "2181:2181"
    environment:
      - ALLOW_ANONYMOUS_LOGIN=yes
#    volumes:
#      - zookeeper_vol:/data
#      - zookeeper_vol:/datalog
#      - zookeeper_vol:/logs
    container_name: zookeeper

  kafka:
    image: bitnami/kafka:latest
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: "localhost"
      KAFKA_ZOOKEEPER_CONNECT: "zookeeper:2181"
#      KAFKA_LOG_DIRS: "/home"
#    volumes:
#      - kafka_vol:/kafka
    depends_on:
      - zookeeper
    container_name: kafka

#volumes:
#  zookeeper_vol: {}
#  kafka_vol: {}

启动一个命令行,生产

docker-compose -f kafa-group.yml up -d
docker exec -it kafka /bin/bash
cd /opt/bitnami/kafka/bin
sh kafka-console-producer.sh --broker-list localhost:9092 --topic test

另开一个命令行,消费

docker exec -it kafka /bin/bash
cd /opt/bitnami/kafka/bin
sh kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test

在生产中输入字符
在这里插入图片描述

消费端接收到

在这里插入图片描述

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部