我正在尝试使用Spark Streaming从kafka主题中读取数据。我能够将消息生成到kafka主题中,但是在使用Spark Streaming从主题中读取数据时,却收到如下所示的错误消息:
ERROR ReceiverTracker: Deregistered receiver for stream 0: Error starting receiver 0 - java.lang.ClassCastException: java.util.HashMap cannot be cast to java.lang.String
下面是代码:
from pyspark import SparkConf, SparkContext
from pyspark.streaming import StreamingContext
from pyspark.streaming.kafka import KafkaUtils
import pprint
conf= SparkConf().setAppName(“streaming test”).setMaster(“yarn-client”)
sc=SparkContext(conf=conf)
ssc=StreamingContext(sc,10)
topic = “newone”
broker = {“metadata.broker.list”: “URL”}
direct = KafkaUtils.createStream(ssc,broker,“test”,{topic:1})
direct.pprint()
ssc.start()
ssc.awaitTermination()
答案 0 :(得分:1)