kafka使用备注

Table of Contents

启动

sudo ./bin/kafka-server-start.sh /usr/local/kafka_2.9.2-0.8.2.1/config/producer.properties

producer.properties配置文件

broker.id=0
port=9092
host.name=127.0.0.1
num.network.threads=2
num.io.threads=8
socket.send.buffer.bytes=1048576
socket.request.max.bytes=104857600
log.dirs=/tmpfka-logs
num.partitions=2
log.flush.interval.messages=10000
log.flush.interval.ms=1000
log.retention.hours=168
log.retention.bytes=1073741824
log.segment.bytes=536870912
log.retention.check.interval.ms=60000
log.cleaner.enable=false
zookeeper.connect=127.0.0.1:2181
zookeeper.connection.timeout.ms=1000000
producer.type=sync
compression.codec=none
serializer.class=kafka.serializer.DefaultEncoder

创建topic

sudo ./bin/kafka-topics.sh --create --topic testtopic --replication-factor 1 --partitions 1 --zookeeper 127.0.0.1:2181

查看topic

所有
sudo ./bin/kafka-topics.sh --list --zookeeper 127.0.0.1:2181
具体
sudo ./bin/kafka-topics.sh --describe --topic testtopic --zookeeper 127.0.0.1:2181

生产消费

生产
sudo ./bin/kafka-console-producer.sh --broker-list 127.0.0.1:9092 --topic testtopic
消费
sudo ./bin/kafka-console-consumer.sh --zookeeper 127.0.0.1:2181 --from-beginning --topic testtopic

Author: josephzeng (josephzeng36@gmail.com)

Last Updated 2015-12-21. Created by Emacs 24.5.1 (Org mode 8.2.10)

Validate