您可以使用 queueStream 从 RDD 队列创建 DStream:
StreamingContext
JavaSparkContext sc = new JavaSparkContext(conf);
org.apache.hadoop.conf.Configuration hconf = HBaseConfiguration.create();
JavaHBaseContext jhbc = new JavaHBaseContext(sc, hconf);
Scan scan1 = new Scan();
scan1.setAttribute(Scan.SCAN_ATTRIBUTES_TABLE_NAME, tableName.getBytes());
// Create RDD
rdd = jhbc.hbaseRDD(tableName, scan1, new Function<Tuple2<ImmutableBytesWritable, Result>, Tuple2<ImmutableBytesWritable, Result>>() {
@Override
public Tuple2<ImmutableBytesWritable, Result> call(Tuple2<ImmutableBytesWritable, Result> immutableBytesWritableResultTuple2) throws Exception {
return immutableBytesWritableResultTuple2;
}
});
// Create streaming context and queue
JavaSparkStreamingContext ssc = new JavaSparkStramingContext(sc);
Queue<JavaRDD<Tuple2<ImmutableBytesWritable, Result> >> queue =new Queue<JavaRDD<Tuple2<ImmutableBytesWritable, Result>>>( );
queue.enqueue(rdd);
JavaDStream<Tuple2<ImmutableBytesWritable, Result>> ssc.queueStream(queue);
PS:你可以只使用 Spark(没有流式传输)