嗨:我是kafka的新手,我按照以下步骤在Mac上安装和初始化kafka:
brew install kafka
我可以看到配置文件是:
/usr/local/etc/kafka/server.properties
/usr/local/etc/kafka/zookeeper.properties
开始kafka
kafka-server-start /usr/local/etc/kafka/server.properties &
创建一个名为“测试”的主题
kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
我可以列出它:
kafka-topics --list --zookeeper localhost:2181
在一个终端中启动生产者并输入一些文本:
kafka-console-producer.sh --broker-list localhost:9092 --topic test
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/x/Documents/zk/server1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/kafka/2.0.0/libexec/libs/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
>1st line
>
开始消费
kafka-console-consumer --bootstrap-server localhost:9092 --topic test --from-beginning
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/x/Documents/zk/server1/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/kafka/2.0.0/libexec/libs/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
无论我在生产者终端中输入什么,消费者都不会打印任何内容。如何解决此问题,我错过了什么吗?
答案 0 :(得分:1)
从https://www.apache.org/dyn/closer.cgi?path=/kafka/2.0.0/kafka_2.11-2.0.0.tgz
下载apache Kafka在任何位置解压缩并在所有终端上执行以下命令,以便执行以下命令,否则您可以替换命令中的安装路径并执行。
export kafka=<location-of-unzipped-directory>
$kafka/bin/zookeeper-server-start.sh $kafka/config/zookeeper.properties
中执行来运行Zookeeper $kafka/bin/kafka-server-start.sh $kafka/config/server.properties
$kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
$kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
代替记住命令,可以在.bashrc或.zshrc中添加以下命令
export kafka="/Users/mac-user/standalone/kafka_2.11-2.0.0"
alias startkafka="$kafka/bin/kafka-server-start.sh $kafka/config/server.properties"
alias startzoo="$kafka/bin/zookeeper-server-start.sh $kafka/config/zookeeper.properties"
alias stopkafka="$kafka/bin/kafka-server-stop.sh"
alias stopzoo="$kafka/bin/zookeeper-server-stop.sh"