Database Reference
In-Depth Information
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")
val names =
scala.io.Source.fromInputStream(namesResource)
.getLines()
.toList
.head
.split(",")
.toSeq
// Generate a sequence of possible products
val products = Seq(
"iPhone Cover" -> 9.99,
"Headphones" -> 5.49,
"Samsung Galaxy Cover" -> 8.95,
Search WWH ::




Custom Search