我正在尝试使用Spark流库从kafka读取json字符串。代码能够连接到kafka代理,但在解码消息时失败。代码的灵感来自于
// calling the parseEvents function
parseEvents(calEventRequest,function(eventList){
console.log(eventList);
//this will print the array after for loop finished
})
function parseEvents(calEventRequest,callback){
var localEventList = new Array();
calEventRequest.execute(function(events){
for(i = 0; i < events.items.length; i++){
var item = events.items[i];
var name = item.summary;
var start = item.dateTime;
localEventList.push(name);
};
if(callback)callback(localEventList);
// If I place a console.log(localEventList) here, the array is populated
});
console.log(localEventList); // But the call here displays an empty array.
}
java.lang.NoSuchMethodError:kafka.message.MessageAndMetadata。(Ljava / lang / String; ILkafka / message / Message; JLkafka / serializer / Decoder; Lkafka / serializer / Decoder;)V 在org.apache.spark.streaming.kafka.KafkaRDD $ KafkaRDDIterator.getNext(KafkaRDD.scala:222) 在org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:73) 在scala.collection.Iterator $$ anon $ 11.hasNext(Iterator.scala:327) 在scala.collection.Iterator $ class.foreach(Iterator.scala:727) 在scala.collection.AbstractIterator.foreach(Iterator.scala:1157) 在scala.collection.generic.Growable $ class。$ plus $ plus $ eq(Growable.scala:48) 在scala.collection.mutable.ArrayBuffer。$ plus $ plus $ eq(ArrayBuffer.scala:103) 在scala.collection.mutable.ArrayBuffer。$ plus $ plus $ eq(ArrayBuffer.scala:47) 在scala.collection.TraversableOnce $ class.to(TraversableOnce.scala:273) 在scala.collection.AbstractIterator.to(Iterator.scala:1157) 在scala.collection.TraversableOnce $ class.toBuffer(TraversableOnce.scala:265)
答案 0 :(得分:0)
问题在于使用的Kafka罐的版本,使用0.9.0.0修复了问题。类kafka.message.MessageAndMetadata是在0.8.2.0中引入的。