O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The producer application

Our producer needs to create a network connection and generate some random purchase event data to send over this connection. First, we will define our object and main method definition. We will then read the random names from the names.csv resource and create a set of products with prices, from which we will generate our random product events:

/**   * A producer application that generates random "product   * events", up to 5 per second, and sends them over a network    * connection */ object StreamingProducer {   def main(args: Array[String]) {     val random = new Random()     // Maximum number of events per second     val MaxEvents = 6     // Read the list of possible names     val namesResource =  this.getClass.getResourceAsStream("/names.csv") ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required