Hello inqisitor. In previous blog we have seen about the predefined Stream receiver of Spark.
In this blog we are going to discuss about Custom receiver of spark so that we can source the data from any .
So if we want to use Custom Receiver than we should know first we are not going to use SparkSession as entry point , if there are not any such use case .
So at first you should add following dependency to build.sbt :
“org.apache.spark” %% “spark-streaming” % “2.0.0”
Now create a class CustomReceiver which should extends Receiver class and override onStart() and onStop().
Here onStart() will contain the code to retrieve data from external source periodically and to store the data to stream using store().
Now what we ned is to configure StreamingContext :
and at final step we have to tell Spark StreamingContext about CustomReceiver :
After all these things we can do transformation on streamed data.Transformation allows the data from the input DStream to be modified :
Now we are much concern about transformatio of spark. Computation may be of following type :
- reduceByKey(func, [numTasks])
- join(otherStream, [numTasks])
- cogroup(otherStream, [numTasks])
I was much curious about how the Computation will be performed on stream. And i got that we can perform Windowed Computation as :
Now you please fasten your seatbelts at this time. and here we go :
You can find complete code here