Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How do you create a spark streaming context?

user-image
Question added by Partha Sarathi Ghosh , Developer
Date Posted: 2018/04/07
Ankit Gaurav Sinha
by Ankit Gaurav Sinha , System Analysts - Team Lead , Cybage Solutions

Hi Partha,                                                                    

A Spark Streaming Context is the entry point of streaming program. Spark Streaming Context can be created only after Spark Configuration or SparkConf is created. SparkConf provides Configuration for a Spark application. Used to set various Spark parameters as key-value pairs. A Streaming Context object can be created from a SparkConf object.

We have to import spark.streaming package for the same.

An example:

import org.apache.spark._

import org.apache.spark.streaming._

val conf = new SparkConf().setAppName(appName).setMaster(master) val streamcontent = new StreamingContext(conf, Seconds())The appName parameter is a name for your application to show on the cluster UI and master is a Spark, Mesos or YARN cluster URL, or a special “local[*]” string to run in local mode.

 Seconds() is the timeframe( seconds in this example) for which data stream is ingested from source.

 

A StreamingContext object can also be created from an existing SparkContext object.

An example:

import org.apache.spark.streaming._

import org.apache.spark.streaming._

val conf = new SparkConf().setAppName(appName).setMaster(master) val streamcontent = new StreamingContext(conf, Seconds(1)) val newstreamcontent = new StreamingContext(streamcontent,Seconds())Hope this will help.

 

 

 

 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.