Streaming with Apache Spark 2.0


Hello geeks we were discussed about Apache Spark 2.0 with hive in earlier blog.

Now i am going to describe how can we use spark to stream the data   .

At first we need to understand this new Spark Streaming architecture  .

Spark 2.0 simplified the API for Streaming and lets us to access stream data in form of DataFrame and DataSet. Hence with new architecture we can process our streamed data according to our business logic with DataFrame. This is the simple concept behind above architecture.

So here we have two approach to use Spark Streaming programmetically :

  • by using predefined receiver , and
  • by creating Custom-Receiver

At first we will stream our data using predefined receiver .

Add the following dependencies  :

“org.apache.spark” %% “spark-core” % “2.0.0”,
“org.apache.spark” %% “spark-sql” % “2.0.0”,
“org.apache.spark” %% “spark-hive” % “2.0.0”,
“org.apache.spark” %% “spark-streaming” % “2.0.0”

Now as we know entry point of Spark in current version is SparkSession . So ,

val sparkSession = SparkSession.builder
.master("local")
.appName("demo")
.getOrCreate()

Now you need stream receiver  :

val dataFrame : DataFrame = sparkSession.read.json("src/main/resources/dummy.json")

Now we get the data of stream here we can perform our any bussines logic with dataframe.

dataFrame.distinct().show()

Find Demo code here.
Continue Reading to Streaming with Custom Receiver.

Thanks

KNOLDUS-advt-sticker

Advertisements

About Rahul Kumar

Software Consultant At Knoldus
This entry was posted in apache spark, big data, Scala and tagged , . Bookmark the permalink.

2 Responses to Streaming with Apache Spark 2.0

  1. Pingback: Streaming with Apache Spark Custom Receiver | Knoldus

  2. Pingback: Streaming With Apache Spark Custom Receiver -

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s