下载安装后,修改好配置文件
先打开服务
kafka-server-start.sh -daemon /usr/kafka/config/server.properties
创建一个topic
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
Created topic "test".
列出所有topic
kafka-topics.sh --list --zookeeper localhost:2181
结果:
test
向topic中发送一些信息
> kafka-console-producer.sh --broker-list localhost:9092 --topic test
hello world !
当然这里如果按照官方文档测试的话会出现一个问题
[2016-09-15 09:38:12,543] ERROR Error when sending message to topic test with key: null, value: 13 bytes with error: (org.apachorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms.
这个原因是用了localhost
,将其改为机器实际的ip地址即可。
接收信息(另起一个命令行)
> kafka-console-consumer.sh --zookeeper localhost:2181 --topic test
当然可以加上一项:--from-beginning
意思很明显就不解释了。