Consumed — Metadata for Consuming Records¶
Consumed<K, V>
describes how to consume records in a topology in the High-Level KStream DSL for the following StreamsBuilder operators:
Consumed<K, V>
is a NamedOperation.
Demo¶
import org.apache.kafka.common.serialization.Serdes
import org.apache.kafka.streams.kstream.Consumed
val consumed = Consumed.`with`(Serdes.Long, Serdes.String)
scala> :type consumed
org.apache.kafka.streams.kstream.Consumed[Long,String]
Creating Instance¶
Consumed
takes the following to be created:
-
Serde<K>
of keys (Apache Kafka) -
Serde<V>
of values (Apache Kafka) -
TimestampExtractor
- Reset Policy (
Topology.AutoOffsetReset
) - Processor Name
Consumed
is created using the factories.
Creating Consumed¶
as¶
Consumed<K, V> as(
String processorName)
with¶
Consumed<K, V> with(
Serde<K> keySerde,
Serde<V> valueSerde)
Consumed<K, V> with(
Serde<K> keySerde,
Serde<V> valueSerde,
TimestampExtractor timestampExtractor,
Topology.AutoOffsetReset resetPolicy)
Consumed<K, V> with(
TimestampExtractor timestampExtractor)
Consumed<K, V> with(
Topology.AutoOffsetReset resetPolicy)
Scala API¶
Scala API for Kafka Streams makes the optional Consumed
metadata an implicit parameter in the StreamsBuilder API.
Moreover, ImplicitConversions
object defines consumedFromSerde
implicit method that creates a Consumed
instance with the key and value Serde
objects available in implicit scope.
And the last but not least, Scala API for Kafka Streams defines Consumed
object with with
factory methods that use implicit key and value Serde
objects.