Created
November 28, 2016 13:31
-
-
Save shirou/8fb3735c7aad37b75ae2ac1f560085a3 to your computer and use it in GitHub Desktop.
dockerでkafka
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# consumer.py | |
# pip install kafka-python すること | |
from kafka import KafkaConsumer, TopicPartition | |
consumer = KafkaConsumer(bootstrap_servers='localhost:32774') # docker ps でport番号しらべる | |
consumer.subscribe(['foobar']) | |
for msg in consumer: | |
print(msg) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2' | |
services: | |
zookeeper: | |
image: wurstmeister/zookeeper | |
ports: | |
- "2181:2181" | |
kafka: | |
build: . | |
ports: | |
- "9092" | |
environment: | |
KAFKA_ADVERTISED_HOST_NAME: 192.168.1.16 ## これ、local macのIPアドレスね | |
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock | |
links: | |
- zookeeper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kafka import KafkaProducer | |
producer = KafkaProducer(bootstrap_servers='localhost:32774') # ここも同じね。 | |
producer.send('foobar', b'another_message').get(timeout=60) |
無事動いた!最終的なキモは links
に zookeeper
を追加することだった。これがないと接続ができない。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ヒアリングしたところ
docker-machine
は使用していない、使うとダメなのかも。使わないで試す。docker-machine
はもう古い?単に Docker for Mac と相性が悪い?docker-compose up
だけで大丈夫みたい