Package org.apache.kafka.streams.kstream
Class Materialized<K,V,S extends StateStore>
- java.lang.Object
-
- org.apache.kafka.streams.kstream.Materialized<K,V,S>
-
- Type Parameters:
K- type of record keyV- type of record valueS- type of state store (note: state stores always have key/value types<Bytes,byte[]>
public class Materialized<K,V,S extends StateStore> extends java.lang.ObjectUsed to describe how aStateStoreshould be materialized. You can either provide a customStateStorebackend through one of the provided methods accepting a supplier or use the default RocksDB backends by providing just a store name.For example, you can read a topic as
KTableand force a state store materialization to access the content via Interactive Queries API:StreamsBuilder builder = new StreamsBuilder(); KTable<Integer, Integer> table = builder.table( "topicName", Materialized.as("queryable-store-name"));- See Also:
Stores
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancachingEnabledprotected org.apache.kafka.common.serialization.Serde<K>keySerdeprotected booleanloggingEnabledprotected java.lang.StringstoreNameprotected StoreSupplier<S>storeSupplierprotected java.util.Map<java.lang.String,java.lang.String>topicConfigprotected org.apache.kafka.common.serialization.Serde<V>valueSerde
-
Constructor Summary
Constructors Modifier Constructor Description protectedMaterialized(Materialized<K,V,S> materialized)Copy constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <K,V,S extends StateStore>
Materialized<K,V,S>as(java.lang.String storeName)Materialize aStateStorewith the given name.static <K,V>
Materialized<K,V,KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>>as(KeyValueBytesStoreSupplier supplier)Materialize aKeyValueStoreusing the providedKeyValueBytesStoreSupplier.static <K,V>
Materialized<K,V,SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>>as(SessionBytesStoreSupplier supplier)Materialize aSessionStoreusing the providedSessionBytesStoreSupplier.static <K,V>
Materialized<K,V,WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>>as(WindowBytesStoreSupplier supplier)Materialize aWindowStoreusing the providedWindowBytesStoreSupplier.static <K,V,S extends StateStore>
Materialized<K,V,S>with(org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde)Materialize aStateStorewith the provided key and valueSerdes.Materialized<K,V,S>withCachingDisabled()Disable caching for the materializedStateStore.Materialized<K,V,S>withCachingEnabled()Enable caching for the materializedStateStore.Materialized<K,V,S>withKeySerde(org.apache.kafka.common.serialization.Serde<K> keySerde)Set the keySerde the materializeStateStorewill use.Materialized<K,V,S>withLoggingDisabled()Disable change logging for the materializedStateStore.Materialized<K,V,S>withLoggingEnabled(java.util.Map<java.lang.String,java.lang.String> config)Indicates that a changelog should be created for the store.Materialized<K,V,S>withValueSerde(org.apache.kafka.common.serialization.Serde<V> valueSerde)Set the valueSerde the materializedStateStorewill use.
-
-
-
Field Detail
-
storeSupplier
protected StoreSupplier<S extends StateStore> storeSupplier
-
storeName
protected java.lang.String storeName
-
valueSerde
protected org.apache.kafka.common.serialization.Serde<V> valueSerde
-
keySerde
protected org.apache.kafka.common.serialization.Serde<K> keySerde
-
loggingEnabled
protected boolean loggingEnabled
-
cachingEnabled
protected boolean cachingEnabled
-
topicConfig
protected java.util.Map<java.lang.String,java.lang.String> topicConfig
-
-
Constructor Detail
-
Materialized
protected Materialized(Materialized<K,V,S> materialized)
Copy constructor.- Parameters:
materialized- theMaterializedinstance to copy.
-
-
Method Detail
-
as
public static <K,V,S extends StateStore> Materialized<K,V,S> as(java.lang.String storeName)
Materialize aStateStorewith the given name.- Type Parameters:
K- key type of the storeV- value type of the storeS- type of theStateStore- Parameters:
storeName- the name of the underlyingKTablestate store; valid characters are ASCII alphanumerics, '.', '_' and '-'.- Returns:
- a new
Materializedinstance with the given storeName
-
as
public static <K,V> Materialized<K,V,WindowStore<org.apache.kafka.common.utils.Bytes,byte[]>> as(WindowBytesStoreSupplier supplier)
Materialize aWindowStoreusing the providedWindowBytesStoreSupplier.- Type Parameters:
K- key type of the storeV- value type of the store- Parameters:
supplier- theWindowBytesStoreSupplierused to materialize the store- Returns:
- a new
Materializedinstance with the given supplier
-
as
public static <K,V> Materialized<K,V,SessionStore<org.apache.kafka.common.utils.Bytes,byte[]>> as(SessionBytesStoreSupplier supplier)
Materialize aSessionStoreusing the providedSessionBytesStoreSupplier.- Type Parameters:
K- key type of the storeV- value type of the store- Parameters:
supplier- theSessionBytesStoreSupplierused to materialize the store- Returns:
- a new
Materializedinstance with the given sup plier
-
as
public static <K,V> Materialized<K,V,KeyValueStore<org.apache.kafka.common.utils.Bytes,byte[]>> as(KeyValueBytesStoreSupplier supplier)
Materialize aKeyValueStoreusing the providedKeyValueBytesStoreSupplier.- Type Parameters:
K- key type of the storeV- value type of the store- Parameters:
supplier- theKeyValueBytesStoreSupplierused to materialize the store- Returns:
- a new
Materializedinstance with the given supplier
-
with
public static <K,V,S extends StateStore> Materialized<K,V,S> with(org.apache.kafka.common.serialization.Serde<K> keySerde, org.apache.kafka.common.serialization.Serde<V> valueSerde)
Materialize aStateStorewith the provided key and valueSerdes. An internal name will be used for the store.- Type Parameters:
K- key typeV- value typeS- store type- Parameters:
keySerde- the keySerdeto use. If theSerdeis null, then the default key serde from configs will be usedvalueSerde- the valueSerdeto use. If theSerdeis null, then the default value serde from configs will be used- Returns:
- a new
Materializedinstance with the given key and value serdes
-
withValueSerde
public Materialized<K,V,S> withValueSerde(org.apache.kafka.common.serialization.Serde<V> valueSerde)
Set the valueSerde the materializedStateStorewill use.- Parameters:
valueSerde- the valueSerdeto use. If theSerdeis null, then the default value serde from configs will be used. If the serialized bytes is null for put operations, it is treated as delete operation- Returns:
- itself
-
withKeySerde
public Materialized<K,V,S> withKeySerde(org.apache.kafka.common.serialization.Serde<K> keySerde)
Set the keySerde the materializeStateStorewill use.- Parameters:
keySerde- the keySerdeto use. If theSerdeis null, then the default key serde from configs will be used- Returns:
- itself
-
withLoggingEnabled
public Materialized<K,V,S> withLoggingEnabled(java.util.Map<java.lang.String,java.lang.String> config)
Indicates that a changelog should be created for the store. The changelog will be created with the provided configs.Note: Any unrecognized configs will be ignored.
- Parameters:
config- any configs that should be applied to the changelog- Returns:
- itself
-
withLoggingDisabled
public Materialized<K,V,S> withLoggingDisabled()
Disable change logging for the materializedStateStore.- Returns:
- itself
-
withCachingEnabled
public Materialized<K,V,S> withCachingEnabled()
Enable caching for the materializedStateStore.- Returns:
- itself
-
withCachingDisabled
public Materialized<K,V,S> withCachingDisabled()
Disable caching for the materializedStateStore.- Returns:
- itself
-
-