找不到 Apache Flink Kafka 连接器

Apache flink Kafka Connector not found

我是 flink/Java/Scala 的新手,所以这可能不是问题,但我们将不胜感激。我一直没能找到一个使用 Flink Kafka 连接器和 Flink 1.13 的例子(对我有用)。

我的项目在这里:https://github.com/sysarcher/flink-scala-tests

我想我无法使用 FlinkKafkaConsumer (link) 我想试用一下。

我正在使用 IntelliJ Idea。该项目是从 tutorial on Flink's website

生成的

以下link用于生成项目:https://ci.apache.org/projects/flink/flink-docs-release-1.13/docs/try-flink/datastream/#how-to-follow-along

遇到错误

$ mvn clean compile
[INFO] ...
[WARNING] Multiple versions of scala libraries detected
[ERROR] /hide/abs/path/github/flink-stuff/frauddetection/src/main/scala/spendreport/FraudDetectionJob.scala:42: error: not found: type FlinkKafkaConsumer
[ERROR]     val kafkaConsumer = new FlinkKafkaConsumer[String]("car.create", new SimpleStringSchema(), properties)
[ERROR]                             ^
[ERROR] one error found

更新:

一个问题是缺少 import 语句:

import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer

我可以使用 mvn clean compile 构建工件,但 IntelliJ 仍然抱怨以下错误:

/long/path/flink-stuff/frauddetection/src/main/scala/spendreport/FraudDetectionJob.scala:30:35
object connectors is not a member of package org.apache.flink.streaming
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer

事实证明问题出在 IntelliJ 的索引(或者其他,我不确定)。我按下 CTRL+SHIFT+A 并输入 Reload All Maven Projects。此后,构建成功。

此评论有帮助:https://lists.apache.org/x/thread.html/rc332d1054886e35af65de4a7c38553e02a2304a2ebdab8197badd94d@%3Cuser.flink.apache.org%3E

It seems sometime IntelliJ does not works well for index, perhaps you could choose mvn -> reimport project from the context menu, if it still not work, perhaps you might try remove the .idea and .iml file and re-open the project again.