18、【SparkStreaming】object not serializable (class: org.apache.kafka.clients.consumer.ConsumerRecord, value: ConsumerRecord
背景:
当SparkStream连接kafka,消费数据时,报错:
object not serializable (class: org.apache.kafka.clients.consumer.ConsumerRecord, value: ConsumerRecord
分析:
消费者的消费记录序列化出现了问题,需要正确的进行序列化。
措施:
在设置sparkconf的时候,指定序列化方式就可以解决了
val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("LocalStreaming").set( "spark.serializer","org.apache.spark.serializer.KryoSerializer" )
效果: