简体   繁体   English

NoSuchMethodError:KafkaConsumer.subscribe

[英]NoSuchMethodError: KafkaConsumer.subscribe

I use the following dependencies: 我使用以下依赖项:

val akkaVersion = "2.4.9"
val kafkaVersion = "0.10.0.1"

dependencies =  ...
  "com.typesafe.akka" %% "akka-actor" % akkaVersion,
  "com.typesafe.akka" %% "akka-cluster" % akkaVersion,
  "com.softwaremill.reactivekafka" %% "reactive-kafka-core" % "0.10.0"   
        excludeAll(
          ExclusionRule("org.slf4j", "log4j-over-slf4j"),
          ExclusionRule("org.apache.kafka", "kafka_2.11")),
   "org.apache.kafka" % "kafka_2.11" % kafkaVersion,
   "org.apache.kafka" % "kafka-clients" % kafkaVersion,
   "org.apache.kafka" % "connect-json" % kafkaVersion

And there is actor: 还有演员:

class ExpKafkaActor extends Actor {

   override def preStart(): Unit = {
    super.preStart()
    val kafka = new ReactiveKafka()

    val publisher = kafka.consume(ConsumerProperties(
      bootstrapServers = "localhost:9092",
      topic = "someTopicName",
      groupId = "groupName",
      valueDeserializer = new StringDeserializer()
    ))

    Source.fromPublisher(publisher).map(m => {
      val message = ProducerMessage(m.value().toUpperCase)
      log.info(s"handle message ${m.value()}")
      message
    })
   }
   ...
}

Then I try start the above actor and the following exception raises: 然后,我尝试启动上述actor,并引发以下异常:

java.lang.NoSuchMethodError:
 org.apache.kafka.clients.consumer.KafkaConsumer.subscribe

I found the following issue , but it doesn't help. 我发现了以下问题 ,但没有帮助。 How can I resolve this API conclict? 如何解决此API冲突?

This issue is due to Kafka client API incompatibility. 此问题是由于Kafka客户端API不兼容引起的。 Please use the right dependency as part of your project pom.xml: 请在项目pom.xml中使用正确的依赖项:

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>{kafka.version}</version>
</dependency>

ex: for Kafka 0.10.2.0, use the following one
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>0.10.2.0</version>
</dependency>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM