其实官网上面已经指明的这个错误了!!!! 甚至还给出了解决方法
官网文档
但是我自己又通俗的总结了一些:
dstream.foreachRDD { rdd =>
val connection = createNewConnection() // executed at the driver
rdd.foreach { record =>
connection.send(record) // executed at the worker
}
}
官网上面说了
connection ---- 执行再driver 端
connection.send ---- 执行再execute端
首先看一个简单的架构(我自己亲手画的!!!!)
我有三个机器: hadoop000, hadoop001, hadoop002,
1 Driver端上面是SparkStreaming程序
2 Driver端会命令Executer端开启一个Receiver去接受数据,
3 Driver上面的StreamingContext会命令底层的SparkContext去执行这个Job。
4 SparkContext会把job再分发给其他的Executer去执行。
…
那么问题就出现再第4步~~~ 分发!!
因为再分发的时候, 是会对对象进行序列化操作。 序列化就需要Serializable接口。