Last active
November 21, 2018 14:43
-
-
Save DanteLore/32b7b3bfc8d456ebb5ad334252cab160 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SaleProducer { | |
// ... | |
def createSale : GenericRecord = { | |
val sale: GenericRecord = new GenericData.Record(schema) | |
sale.put("beer_id", beerIds(Random.nextInt(beerIds.size)).toInt) | |
sale.put("bar", Random.nextInt(4) + 1) // There are 4 bars (i.e. 4 cash registers) | |
sale.put("price", if(Random.nextDouble() > 0.75) 2 else 1) // Beer festival; 1 token per half | |
sale | |
} | |
def main(args: Array[String]): Unit = { | |
while (true) { | |
producer.send(new ProducerRecord[String, GenericRecord](topic, createSale)).get() | |
Thread.sleep(1000) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment