Coding our first Spark Streaming job
In this section, we will code and execute our first Spark Streaming job in Scala. We will also simulate the streaming data by creating a temporary stream.
Creating a stream producer
Perform the following steps to create a stream producer which continuously reads the input data provided by the user from the console and then further submits that data to a socket:
Open and edit your
Spark-Examples
project and create a new Scala package and class namedchapter.nine.StreamProducer.java
.Next, edit
StreamProducer.java
and add the following piece of code:import java.net.*; import java.io.*; public class StreamProducer { public static void main(String[] args) { if (args == null || args.length < 1) { System.out.println("Usage - java chapter.nine.StreamProducer <port#>"); System.exit(0); } System.out.println("Defining new Socket on " + args[0]); try (ServerSocket soc = new ServerSocket(Integer.parseInt(args[0]))) { System.out...