LoginSignup
4
3

More than 5 years have passed since last update.

Apache Kafkaをローカルで簡単に試す方法

Last updated at Posted at 2016-12-07

Dockerでkafkaを立てる

公式イメージがなかったので人気があるものを選択しましたー

$ git clone https://github.com/wurstmeister/kafka-docker
$ cd kafka-docker
$ git checkout 0.9.0.1
$ vi docker-compose-single-broker.yml
zookeeper:
  image: wurstmeister/zookeeper
  ports:
    - "2181:2181"
kafka:
  build: .
  ports:
    - "9092:9092"
  links:
    - zookeeper:zk
  environment:
    KAFKA_ADVERTISED_HOST_NAME: 192.168.99.100
    KAFKA_CREATE_TOPICS: "test:1:1" 
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
$ docker-compose -f docker-compose-single-broker.yml up -d

クライアント

クライアントインストール

$ brew install kafka 

コマンド

お好きなようにいじいじしますー

# 確認
$ kafka-topics --describe --zookeeper 192.168.99.100:2181

# トピック一覧
$ kafka-topics --list --zookeeper 192.168.99.100:2181

# 生成
$ kafka-topics --create --zookeeper 192.168.99.100:2181 --replication-factor 1 --partitions 1 --topic test_topic

# 削除
$ kafka-topics --delete --zookeeper 192.168.99.100:2181 --replication-factor 1 --partitions 1 --topic test_topic

# プロデュース
kafka-console-producer --broker-list 192.168.99.100:9092 --topic test_topic

# コンシューム
kafka-console-consumer --zookeeper 192.168.99.100:2181 --topic test_topic --from-beginning

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3