# Apache Kafka & Zookeeper Run a message queue with Apache Kafka v2.8.1 & Apache ZooKeeper v3.8.0 ## System Requirements - [Docker](https://www.docker.com/) - [Apache Kafka v2.8.x](https://www.apache.org/dyn/closer.cgi?path=/kafka/3.2.0/kafka_2.13-3.2.0.tgz) ## Docker Compose ```yaml version: '3' services: zookeeper: image: 'zookeeper:3.8.0' container_name: zookeeper380 ports: - '2181:2181' environment: - ALLOW_ANONYMOUS_LOGIN=yes kafka: image: 'bitnami/kafka:2.8.1' container_name: kafka281 ports: - '9092:9092' environment: - KAFKA_BROKER_ID=1 - KAFKA_CFG_LISTENERS=PLAINTEXT://:9092 - KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 - KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181 - ALLOW_PLAINTEXT_LISTENER=yes depends_on: - zookeeper ``` ## Quick Start ### 1. Start the server Used by [Docker Compose](https://docs.docker.com/compose/) ```shell $ docker-compose up -d ``` ### 2. Create a topic ```shell $ kafka-topics.sh --create --topic test --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 Created topic "test". $ kafka-topics.sh --list --bootstrap-server localhost:9092 test ``` ### 3. Send some messages ```shell $ kafka-console-producer.sh --topic test --bootstrap-server localhost:9092 ``` ### 4. Start a consumer ```shell # Get message from beginning $ kafka-console-consumer.sh --topic test --from-beginning --bootstrap-server localhost:9092 # Get message from current $ kafka-console-consumer.sh --topic test --bootstrap-server localhost:9092 # Get message from how far behind the end of the log they are $ kafka-console-consumer.sh --topic test --bootstrap-server localhost:9092 --group groupa ```