我的kafka客户客户端无法在Mac上运行,为什么?

时间:2018-11-06 13:35:58

标签: macos apache-kafka

嗨:我是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]

无论我在生产者终端中输入什么,消费者都不会打印任何内容。如何解决此问题,我错过了什么吗?

1 个答案:

答案 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>

  1. 通过在上述终端$kafka/bin/zookeeper-server-start.sh $kafka/config/zookeeper.properties中执行来运行Zookeeper
  2. 运行kafka经纪人:$kafka/bin/kafka-server-start.sh $kafka/config/server.properties
  3. 运行生产者:$kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
  4. 运行消费者:$kafka/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning
  5. 在生产者中键入可以在消费者中看到输出的任何内容

这是图片 producer-consumer console

代替记住命令,可以在.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"