Skip to content

Instantly share code, notes, and snippets.

View enothereska's full-sized avatar

Eno Thereska enothereska

View GitHub Profile
@enothereska
enothereska / interactive-queries_list-app-instances.md
Last active October 31, 2018 16:27
List all running instances of this application
# List all running instances of this application
$ http://localhost:7070/kafka-music/instances
[
	{
		"host": "localhost",
 "port": 7070,
@enothereska
enothereska / interactive-queries_app-instances-for-a-store.md
Created October 3, 2016 13:11
List running app instances that currently manage (parts of) state store "top-five-songs"
# List running app instances that currently manage (parts of) state store "top-five-songs"
$ http://localhost:7070/kafka-music/instances/top-five-songs
[
	{
		"host": "localhost",
 "port": 7070,
# Get all the top-5 charts across all instances
$ http://localhost:7070/kafka-music/charts/top-five
[
  {
    "artist":"Hilltop Hoods",
 "album":"The Calling",
@enothereska
enothereska / interactive-queries_top-five-charts-genre.md
Created October 3, 2016 14:34
Get the top-5 charts for genre 'punk'
# Get all the top-5 charts across all instances
$ http://localhost:7070/kafka-music/charts/genre/punk
[
  {
    "artist":"Wheres The Pope?",
 "album":"PSI",
@enothereska
enothereska / interactive-queries_song-id.md
Created October 3, 2016 14:38
Get details for a particular song
# Get all the top-5 charts across all instances
$ http://localhost:7070/kafka-music/song/9
{
  "artist":"N.W.A",
  "album":"Straight Outta Compton",
 "name":"Gangsta Gangsta"
@enothereska
enothereska / dataflow-example.java
Created April 30, 2017 09:10
A Dataflow example with triggers and watermarks
PCollection<KV<String, Integer>> scores = input
.apply(Window.into(FixedWindows.of(Duration.standardMinutes(2)))
.triggering(
AtWatermark()
.withEarlyFirings(AtPeriod(Duration.standardMinutes(1)))
.withLateFirings(AtCount(1)))
.accumulatingAndRetractingFiredPanes())
.apply(Sum.integersPerKey())
@enothereska
enothereska / ktable-example.java
Last active June 20, 2017 05:56
A KTable example
KTable<Windowed<String>, Long> aggregated = inputStream
.groupByKey()
.reduce((aggValue, newValue) -> aggValue + newValue,
TimeWindows.of(TimeUnit.MINUTES.toMillis(2))
.until(TimeUnit.DAYS.toMillis(1) /* keep for one day */),
"queryStoreName");
// Get the window store named "queryStoreName"
ReadOnlyWindowStore<String, Long> windowStore =
streams.store("queryStoreName", QueryableStoreTypes.windowStore());
// Fetch values for the key "europe" for all of the windows available in this application instance.
// To get *all* available windows we fetch windows from the beginning of time until now.
long timeFrom = 0; // beginning of time = oldest available
long timeTo = System.currentTimeMillis(); // now (in processing-time)
WindowStoreIterator<Long> iterator = windowStore.fetch("europe", timeFrom, timeTo);
while (iterator.hasNext()) {