Package org.apache.kafka.streams.kstream
Class Consumed<K,V>
- java.lang.Object
-
- org.apache.kafka.streams.kstream.Consumed<K,V>
-
- Type Parameters:
K
- type of record keyV
- type of record value
- Direct Known Subclasses:
ConsumedInternal
public class Consumed<K,V> extends java.lang.Object
TheConsumed
class is used to define the optional parameters when usingStreamsBuilder
to build instances ofKStream
,KTable
, andGlobalKTable
.For example, you can read a topic as
KStream
with a custom timestamp extractor and specify the corresponding key and value serdes like:
Similarly, you can read a topic asStreamsBuilder builder = new StreamsBuilder(); KStream<String, Long> stream = builder.stream( "topicName", Consumed.with(Serdes.String(), Serdes.Long()) .withTimestampExtractor(new LogAndSkipOnInvalidTimestamp()));
KTable
with a customauto.offset.reset
configuration and force a state storematerialization
to access the content via interactive queries:StreamsBuilder builder = new StreamsBuilder(); KTable<Integer, Integer> table = builder.table( "topicName", Consumed.with(AutoOffsetReset.LATEST), Materialized.as("queryable-store-name"));
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.kafka.common.serialization.Serde<K>
keySerde
protected Topology.AutoOffsetReset
resetPolicy
protected TimestampExtractor
timestampExtractor
protected org.apache.kafka.common.serialization.Serde<V>
valueSerde
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
int
hashCode()
static <K,V>
Consumed<K,V>with(org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde)
Create an instance ofConsumed
with key and valueSerde
s.static <K,V>
Consumed<K,V>with(org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde, TimestampExtractor timestampExtractor, Topology.AutoOffsetReset resetPolicy)
Create an instance ofConsumed
with the supplied arguments.static <K,V>
Consumed<K,V>with(TimestampExtractor timestampExtractor)
Create an instance ofConsumed
with aTimestampExtractor
.static <K,V>
Consumed<K,V>with(Topology.AutoOffsetReset resetPolicy)
Create an instance ofConsumed
with aTopology.AutoOffsetReset
.Consumed<K,V>
withKeySerde(org.apache.kafka.common.serialization.Serde<K> keySerde)
Configure the instance ofConsumed
with a keySerde
.Consumed<K,V>
withOffsetResetPolicy(Topology.AutoOffsetReset resetPolicy)
Configure the instance ofConsumed
with aTopology.AutoOffsetReset
.Consumed<K,V>
withTimestampExtractor(TimestampExtractor timestampExtractor)
Configure the instance ofConsumed
with aTimestampExtractor
.Consumed<K,V>
withValueSerde(org.apache.kafka.common.serialization.Serde<V> valueSerde)
Configure the instance ofConsumed
with a valueSerde
.
-
-
-
Field Detail
-
keySerde
protected org.apache.kafka.common.serialization.Serde<K> keySerde
-
valueSerde
protected org.apache.kafka.common.serialization.Serde<V> valueSerde
-
timestampExtractor
protected TimestampExtractor timestampExtractor
-
resetPolicy
protected Topology.AutoOffsetReset resetPolicy
-
-
Method Detail
-
with
public static <K,V> Consumed<K,V> with(org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde, TimestampExtractor timestampExtractor, Topology.AutoOffsetReset resetPolicy)
Create an instance ofConsumed
with the supplied arguments.null
values are acceptable.- Type Parameters:
K
- key typeV
- value type- Parameters:
keySerde
- the key serde. Ifnull
the default key serde from config will be usedvalueSerde
- the value serde. Ifnull
the default value serde from config will be usedtimestampExtractor
- the timestamp extractor to used. Ifnull
the default timestamp extractor from config will be usedresetPolicy
- the offset reset policy to be used. Ifnull
the default reset policy from config will be used- Returns:
- a new instance of
Consumed
-
with
public static <K,V> Consumed<K,V> with(org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde)
Create an instance ofConsumed
with key and valueSerde
s.- Type Parameters:
K
- key typeV
- value type- Parameters:
keySerde
- the key serde. Ifnull
the default key serde from config will be usedvalueSerde
- the value serde. Ifnull
the default value serde from config will be used- Returns:
- a new instance of
Consumed
-
with
public static <K,V> Consumed<K,V> with(TimestampExtractor timestampExtractor)
Create an instance ofConsumed
with aTimestampExtractor
.- Type Parameters:
K
- key typeV
- value type- Parameters:
timestampExtractor
- the timestamp extractor to used. Ifnull
the default timestamp extractor from config will be used- Returns:
- a new instance of
Consumed
-
with
public static <K,V> Consumed<K,V> with(Topology.AutoOffsetReset resetPolicy)
Create an instance ofConsumed
with aTopology.AutoOffsetReset
.- Type Parameters:
K
- key typeV
- value type- Parameters:
resetPolicy
- the offset reset policy to be used. Ifnull
the default reset policy from config will be used- Returns:
- a new instance of
Consumed
-
withKeySerde
public Consumed<K,V> withKeySerde(org.apache.kafka.common.serialization.Serde<K> keySerde)
Configure the instance ofConsumed
with a keySerde
.- Parameters:
keySerde
- the key serde. Ifnull
the default key serde from config will be used- Returns:
- this
-
withValueSerde
public Consumed<K,V> withValueSerde(org.apache.kafka.common.serialization.Serde<V> valueSerde)
Configure the instance ofConsumed
with a valueSerde
.- Parameters:
valueSerde
- the value serde. Ifnull
the default value serde from config will be used- Returns:
- this
-
withTimestampExtractor
public Consumed<K,V> withTimestampExtractor(TimestampExtractor timestampExtractor)
Configure the instance ofConsumed
with aTimestampExtractor
.- Parameters:
timestampExtractor
- the timestamp extractor to used. Ifnull
the default timestamp extractor from config will be used- Returns:
- this
-
withOffsetResetPolicy
public Consumed<K,V> withOffsetResetPolicy(Topology.AutoOffsetReset resetPolicy)
Configure the instance ofConsumed
with aTopology.AutoOffsetReset
.- Parameters:
resetPolicy
- the offset reset policy to be used. Ifnull
the default reset policy from config will be used- Returns:
- this
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-