union(otherStream)

union(otherStream)

Return a new DStream that contains the union of the elements in the source DStream and other DStream.

import org.apache.spark._
import org.apache.spark.streaming._
import org.apache.spark.streaming.StreamingContext._ // not necessary since Spark 1.3

// Create a local StreamingContext with two working thread and batch interval of 1 second.
// The master requires 2 cores to prevent from a starvation scenario.

val conf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
sc.stop
val ssc = new StreamingContext(conf, Seconds(1))
val lines = ssc.socketTextStream("localhost", 9999)
val lines_another = ssc.socketTextStream("10.0.0.202", 9999)
val combo_lines=lines.union(lines_another)

Last updated