Skip to content

Instantly share code, notes, and snippets.

@DanteLore
Last active November 21, 2018 14:43
Show Gist options
  • Save DanteLore/32b7b3bfc8d456ebb5ad334252cab160 to your computer and use it in GitHub Desktop.
Save DanteLore/32b7b3bfc8d456ebb5ad334252cab160 to your computer and use it in GitHub Desktop.
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