kafka_2.11-0.11.0.0安装以及使用
(1)配置zookeeper地址
vim /data/kafka_2.11-0.11.0.0/config/server.properties
zookeeper.connect=localhost:2181,localhost:2182,localhost:2183
(2)配置内存
vim /data/kafka_2.11-0.11.0.0/bin/kafka-server-start.sh
if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then
export KAFKA_HEAP_OPTS="-Xmx256m -Xms256m"
fi
(3)敲黑板!修改对外的IP地址,否则kafka在别的机器上无法发布和订阅
[root@iZ2zei0nwllapkwklisoncZ kafka_2.11-0.11.0.0]# vim config/server.properties
advertised.listeners=PLAINTEXT://123.56.13.70:9092
1.3 启动
sh/data/kafka_2.11-0.11.0.0/bin/kafka-server-start.sh /data/kafka_2.11-0.11.0.0/config/server.properties
2. 发送和订阅消息
2.1 创建主题
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
2.2 查看主题
[root@iZ2zei0nwllapkwklisoncZ kafka_2.11-0.11.0.0]# bin/kafka-topics.sh --list --zookeeper localhost:2181
test
2.3 发送消息produce
[root@iZ2zei0nwllapkwklisoncZ kafka_2.11-0.11.0.0]# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
>我是高天悦
>
2.4 接收消息consume
[root@iZ2zei0nwllapkwklisoncZ kafka_2.11-0.11.0.0]# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
this is a msg
this is another msg
你好
来源:http://blog.csdn.net/kkgbn/article/details/77540491
请先 后发表评论~