当我尝试使用scala将融合的kafka集群与简单的消费者代码连接起来时。但连接失败并引发异常“
线程“main”org.apache.kafka.common.kafkaexception中出现异常:无法构造kafka使用者
但是我可以在其他机器上连接相同的集群。我在书堆里引用了类似的帖子,但没有一个是我的方式。
import java.util.Collections
import org.apache.kafka.clients.consumer.KafkaConsumer
import scala.collection.JavaConverters._
object kafkaconnect {
def main(args: Array[String]): Unit = {
import java.util.Properties
val TOPIC="test"
val props = new Properties()
props.put("bootstrap.servers", "conflunetcluster:9092")
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
props.put("group.id", "something")
props.put("enable.auto.commit", "true")
props.put("auto.commit.interval.ms", "1000")
props.put("session.timeout.ms", "30000")
props.put("enable.partition.eof", "false")
println(props)
println("beforeconsume")
val consumer = new KafkaConsumer[String, String](props)
println(consumer)
consumer.subscribe(Collections.singletonList(TOPIC))
consumer.listTopics()
println("2")
while(true){
val records=consumer.poll(100)
for (record<-records.asScala){
println(record)
}
}
}
}
Build.SBT
name := "kafkatest"
version := "0.1"
scalaVersion := "2.11.12"
libraryDependencies += "org.apache.kafka" % "kafka-clients" % "1.0.0"
也请找到堆栈跟踪
"C:\Program Files\Java\jdk1.8.0_192\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Educational Edition 2018.3.1\lib\idea_rt.jar=59817:C:\Program Files\JetBrains\IntelliJ IDEA Educational Edition 2018.3.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_192\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_192\jre\lib\rt.jar;C:\Users\756661\IdeaProjects\kafkatest\target\scala-2.11\classes;C:\Users\756661\.ivy2\cache\org.scala-lang\scala-library\jars\scala-library-2.11.12.jar;C:\Users\756661\.ivy2\cache\org.slf4j\slf4j-api\jars\slf4j-api-1.7.25.jar;C:\Users\756661\.ivy2\cache\org.apache.kafka\kafka-clients\jars\kafka-clients-1.0.0.jar;C:\Users\756661\.ivy2\cache\org.lz4\lz4-java\jars\lz4-java-1.4.jar;C:\Users\756661\.ivy2\cache\org.xerial.snappy\snappy-java\bundles\snappy-java-1.1.4.jar" kafkaconnect
{key.deserializer=org.apache.kafka.common.serialization.StringDeserializer, auto.commit.interval.ms=1000, bootstrap.servers=ashaplq00005:9092, enable.partition.eof=false, enable.auto.commit=true, group.id=something, value.deserializer=org.apache.kafka.common.serialization.StringDeserializer, session.timeout.ms=30000}
beforeconsume
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" org.apache.kafka.common.KafkaException: Failed to construct kafka consumer
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:781)
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:635)
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:617)
at kafkaconnect$.main(kafkaconnect.scala:29)
at kafkaconnect.main(kafkaconnect.scala)
Caused by: org.apache.kafka.common.config.ConfigException: No resolvable bootstrap urls given in bootstrap.servers
at org.apache.kafka.clients.ClientUtils.parseAndValidateAddresses(ClientUtils.java:64)
at org.apache.kafka.clients.consumer.KafkaConsumer.<init>(KafkaConsumer.java:698)
... 4 more
Process finished with exit code 1
1条答案
按热度按时间bzzcjhmw1#
从stacktrace,您的消费者无法连接到
conflunetcluster:9092
.是打字错误吗?应该是吗
confluentcluster:9092
?首先尝试使用命令行工具连接到集群(例如
bin/kafka-topics.sh --list --bootstrap-server localhost:9092
)