Skip to content

Instantly share code, notes, and snippets.

@terrhorn
Created February 16, 2016 17:44
Show Gist options
  • Select an option

  • Save terrhorn/af81b8ecee66edbfc3ba to your computer and use it in GitHub Desktop.

Select an option

Save terrhorn/af81b8ecee66edbfc3ba to your computer and use it in GitHub Desktop.
Batch Events in KeenClient-Scala
val collectionName = "my_event_collection" // the name of your collection
val events = ArrayBuffer.empty[String] // an array buffer to hold all of the events that we'll batch
// populate the array with 5000 fake events
for(i <- 1 to 5000) {
events.append(s"""{"foo": { "count": $i, "bar": "baz"} }""")
}
// split events into 5 batches of 1000 events, and send each batch to Keen
for(batch <- events.grouped(1000)) {
// send the batch and await the response
val response = Await.result(
keen.addEvents(s"""{"$collectionName": [${batch.mkString(",")}]}"""),
4.seconds
)
// show the output of each request
response.statusCode match {
case 200 => print("SUCCESS!")
case _ => print("WOMP WOMP")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment