Spark Streaming使用Scala插入到Hbase问题
我正在尝试从卡夫卡消息中读取记录并将其放入Hbase。尽管scala脚本运行时没有任何问题,但插入没有发生。请帮帮我 输入: 行键1,1 行键2,2 以下是我正在使用的代码:Spark Streaming使用Scala插入到Hbase问题,scala,stream,apache-spark,Scala,Stream,Apache Spark,我正在尝试从卡夫卡消息中读取记录并将其放入Hbase。尽管scala脚本运行时没有任何问题,但插入没有发生。请帮帮我 输入: 行键1,1 行键2,2 以下是我正在使用的代码: object Blaher { def blah(row: Array[String]) { val hConf = new HBaseConfiguration() val hTable = new HTable(hConf, "test") val thePut = new Put(B
object Blaher {
def blah(row: Array[String]) {
val hConf = new HBaseConfiguration()
val hTable = new HTable(hConf, "test")
val thePut = new Put(Bytes.toBytes(row(0)))
thePut.add(Bytes.toBytes("cf"), Bytes.toBytes("a"), Bytes.toBytes(row(1)))
hTable.put(thePut)
}
}
object TheMain extends Serializable{
def run() {
val ssc = new StreamingContext(sc, Seconds(1))
val topicmap = Map("test" -> 1)
val lines = KafkaUtils.createStream(ssc,"127.0.0.1:2181", "test-consumer-group",topicmap).map(_._2)
val words = lines.map(line => line.split(",")).map(line => (line(0),line(1)))
val store = words.foreachRDD(rdd => rdd.foreach(Blaher.blah))
ssc.start()
}
}
TheMain.run()
从HTable的flushCommits方法的API文档:执行所有缓冲Put操作。您应该在blah方法的末尾调用它-看起来它们当前正在被缓冲,但从未执行或在某个随机时间执行 创建SparkContext时,您为Spark分配了多少个核心?sc?看起来问题在于将rdd转换为阵列。Somehome foreach rdd调用Blaher.blah方法时发生错误。是否仍然可以将记录作为数组传递并将其插入hbase?