拉取Kafka镜像:
docker pull confluentinc/cp-kafka
启动Zookeeper:
docker run -d --name zookeeper --link kafka:kafka -e KAFKA_ZOOKEEPER_CONNECT=kafka:9092 confluentinc/cp-zookeeper
启动Kafka Broker:
docker run -d --name kafka --link zookeeper:zookeeper -e KAFKA_ZOOKEEPER_CONNECT=zookeeper:9092 -e KAFKA_BROKER_ID=0 -p 9092:9092 confluentinc/cp-kafka
创建Topic:
docker exec kafka kafka-topics.sh --create --topic my-topic --bootstrap-server kafka:9092 --replication-factor 1 --partitions 1
生产者与消费者配置:
通过上述步骤,您可以快速搭建并运行Kafka集群,从而简化整个搭建流程。