Created
February 16, 2016 17:44
-
-
Save terrhorn/af81b8ecee66edbfc3ba to your computer and use it in GitHub Desktop.
Batch Events in KeenClient-Scala
This file contains hidden or 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
| 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