Home > Archives > kafka实战

kafka实战

Publish:

Kafka安装与使用

Kafka 使用Zookeeper 来保存相关配置信息,Kafka及Zookeeper 依赖Java 运行环境。

wget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/2.3.0/kafka_2.12-2.3.0.tgz
tar zxvf kafka_2.12-2.3.0.tgz
cd kafka
# start zookeeper
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
# start kafka
bin/kafka-server-start.sh config/server.properties &
# create topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
bin/kafka-topics.sh --list --zookeeper localhost:2181
# producer 和 consumer 可以同时开启,这样一个窗口输入,另一个窗口输出
# producer
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
> Hello world!
> Hello Kafka!
# consumer
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
cp config/server.properties config/server-1.properties
config/server-1.properties:
    broker.id=1
    port=9093
    log.dir=/tmp/kafka-logs-1
bin/kafka-server-start.sh config/server-1.properties &

后期再考虑

参考

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo