Skip to content

Instantly share code, notes, and snippets.

@urstory
Created September 10, 2019 08:34
Show Gist options
  • Save urstory/dfdb9e0b10fd8109b0d8fd27fe227573 to your computer and use it in GitHub Desktop.
Save urstory/dfdb9e0b10fd8109b0d8fd27fe227573 to your computer and use it in GitHub Desktop.
kafka docker-compose & test
docker-compose.yml 파일
version: '2'
networks:
test:
services:
zookeeper:
image: wurstmeister/zookeeper:3.4.6
container_name: zookeeper
ports:
- "2181:2181"
networks:
- test
kafka:
image: wurstmeister/kafka:2.12-2.0.1
container_name: kafka
environment:
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
KAFKA_ADVERTISED_HOST_NAME: 127.0.0.1
KAFKA_ADVERTISED_PORT: 9092
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
volumes:
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "9092:9092"
depends_on:
- zookeeper
networks:
- test
----------------
kafka 를 다운로드 받아 압축을 해제한 후 아래와 같이 명령을 실행한다.
zookeer의 역할은 어떤 kafka가 살아있는지 알려주는 역살을 수행한다. 실제 메시지 발행과 읽어오기는 kafka서버에 붙어서 실행한다.
./kafka-topics.sh -create -topic test_topic --zookeeper localhost:2181 --partitions 1 --replication-factor 1
./kafka-topics.sh --zookeeper localhost:2181 --list
./kafka-console-producer.sh --broker-list localhost:9092 --topic test_topic
./kafka-console-consumer.sh --topic test_topic --bootstrap-server localhost:9092 --from-beginning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment