Queryable State for Kafka Streamsを使ってみた
- 3. • 2011/04
• 2015/09
•
• Druid (KDP, 2015)
• RDB NoSQL ( , 2016; : HBase )
• ESP8266 Wi-Fi IoT (KDP, 2016)
•
• (DEIM 2014)
• (WebDB Forum 2014)
• Spark Streaming (Spark Meetup December 2015)
• Kafka AWS Kinesis (Apache Kafka Meetup Japan #1; 2016)
• (FutureOfData; 2016)
3
- 8. Apache Kafka Version 0.10.1.0
• New Features
• [KAFKA-1464] - Add a throttling option to the Kafka replication tool
• [KAFKA-3176] - Allow console consumer to consume from
particular partitions when new consumer is used.
• [KAFKA-3492] - support quota based on authenticated user name
• [KAFKA-3776] - Unify store and downstream caching in streams
• [KAFKA-3858] - Add functions to print stream topologies
�� [KAFKA-3909] - Queryable state for Kafka Streams
• [KAFKA-4015] - Change cleanup.policy config to accept a list of
valid policies
• [KAFKA-4093] - Cluster id
8
- 17. Kafka Streams
• Stateful transformations count
KafkaStreams streams = null;
KStreamBuilder builder = new KStreamBuilder();
KStream<String, String> textLines =
builder.stream(stringSerde, stringSerde, inputStream);
KStream<String, Long> wordCounts =
textLines
.flatMapValues(value -> ...)
.groupBy((key, word) -> word)
.count(storeName)
.toStream();
wordCounts.to(stringSerde, longSerde, outputStream);
streams = new KafkaStreams(builder, conf);
17
- 18. Queryable State Streams
• Streams o.a.k.streams.KafkaStreams
KafkaStreams streams = ...;
String key = "kafka";
ReadOnlyKeyValueStore<String, Long> store =
streams.store(
storeName,
QueryableStoreTypes.<String, Long>keyValueStore());
Long value = store.get(key);
return value;
18
- 19. Queryable State Streams
• API
KafkaStreams streams = ...;
get("/results/:key",
(req, res) -> {
String key = req.params(":key");
ReadOnlyKeyValueStore<String, Long> store =
streams.store(
storeName,
QueryableStoreTypes.<String, Long>keyValueStore());
Long value = store.get(key);
return value;
});
19
- 22. $ java -cp target/kafka_streams_example-1.0-SNAPSHOT.jar
org.saekiyoshiyasu.App
kafka -> null
...
kafka -> 5
$ ./bin/kafka-console-producer.sh --topic input-stream
--broker-list 127.0.0.1:9092
What is Kafka good for?
...
22