April 2017
Intermediate to advanced
532 pages
12h 39m
English
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") ...Read now
Unlock full access