DZone
Big Data Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Big Data Zone > Streaming with Apache Spark 2.0

Streaming with Apache Spark 2.0

Let's learn how to do streaming in Apache Spark 2.0 — Scala with examples included.

Rahul Kumar user avatar by
Rahul Kumar
·
Oct. 09, 16 · Big Data Zone · Tutorial
Like (6)
Save
Tweet
5.16K Views

Join the DZone community and get the full member experience.

Join For Free

Hello geeks! We discussed Apache Spark 2.0 with Hive in an earlier blog. Now I am going to describe how can we use spark to stream the data. 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

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.readStream.load("your/path")

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

dataFrame.distinct().show()

Find the demo code here.

Apache Spark

Published at DZone with permission of Rahul Kumar, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 8 Must-Have Project Reports You Can Use Today
  • 12 Modern CSS Techniques For Older CSS Problems
  • DZone's Article Submission Guidelines
  • Biometric Authentication: Best Practices

Comments

Big Data Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo