@Evolving public class Stores extends java.lang.Object
When using the high-level DSL, i.e., StreamsBuilder
, users create
StoreSupplier
s that can be further customized via
Materialized
.
For example, a topic read as KTable
can be materialized into an
in-memory store with custom key/value serdes and caching disabled:
StreamsBuilder builder = new StreamsBuilder();
KeyValueBytesStoreSupplier storeSupplier = Stores.inMemoryKeyValueStore("queryable-store-name");
KTable<Long,String> table = builder.table(
"topicName",
Materialized.as(storeSupplier)
.withKeySerde(Serdes.Long())
.withValueSerde(Serdes.String())
.withCachingDisabled());
When using the Processor API, i.e., Topology
, users create
StoreBuilder
s that can be attached to Processor
s.
For example, you can create a windowed
RocksDB store with custom
changelog topic configuration like:
Topology topology = new Topology();
topology.addProcessor("processorName", ...);
Map<String,String> topicConfig = new HashMap<>();
StoreBuilder<WindowStore<Integer, Long>> storeBuilder = Stores
.windowStoreBuilder(
Stores.persistentWindowStore("queryable-store-name", ...),
Serdes.Integer(),
Serdes.Long())
.withLoggingEnabled(topicConfig);
topology.addStateStore(storeBuilder, "processorName");
Modifier and Type | Class | Description |
---|---|---|
static interface |
Stores.InMemoryKeyValueFactory<K,V> |
Deprecated.
|
static interface |
Stores.KeyValueFactory<K,V> |
|
static interface |
Stores.PersistentKeyValueFactory<K,V> |
Deprecated.
|
static class |
Stores.StoreFactory |
|
static class |
Stores.ValueFactory<K> |
The factory for creating off-heap key-value stores.
|
Constructor | Description |
---|---|
Stores() |
Modifier and Type | Method | Description |
---|---|---|
static Stores.StoreFactory |
create(java.lang.String name) |
|
static KeyValueBytesStoreSupplier |
inMemoryKeyValueStore(java.lang.String name) |
Create an in-memory
KeyValueBytesStoreSupplier . |
static <K,V> StoreBuilder<KeyValueStore<K,V>> |
keyValueStoreBuilder(KeyValueBytesStoreSupplier supplier,
Serde<K> keySerde,
Serde<V> valueSerde) |
Creates a
StoreBuilder than can be used to build a KeyValueStore . |
static KeyValueBytesStoreSupplier |
lruMap(java.lang.String name,
int maxCacheSize) |
Create a LRU Map
KeyValueBytesStoreSupplier . |
static KeyValueBytesStoreSupplier |
persistentKeyValueStore(java.lang.String name) |
Create a persistent
KeyValueBytesStoreSupplier . |
static SessionBytesStoreSupplier |
persistentSessionStore(java.lang.String name,
long retentionPeriod) |
Create a persistent
SessionBytesStoreSupplier . |
static WindowBytesStoreSupplier |
persistentWindowStore(java.lang.String name,
long retentionPeriod,
int numSegments,
long windowSize,
boolean retainDuplicates) |
Create a persistent
WindowBytesStoreSupplier . |
static <K,V> StoreBuilder<SessionStore<K,V>> |
sessionStoreBuilder(SessionBytesStoreSupplier supplier,
Serde<K> keySerde,
Serde<V> valueSerde) |
Creates a
StoreBuilder that can be used to build a SessionStore . |
static <K,V> StoreBuilder<WindowStore<K,V>> |
windowStoreBuilder(WindowBytesStoreSupplier supplier,
Serde<K> keySerde,
Serde<V> valueSerde) |
Creates a
StoreBuilder that can be used to build a WindowStore . |
public static KeyValueBytesStoreSupplier persistentKeyValueStore(java.lang.String name)
KeyValueBytesStoreSupplier
.name
- name of the store (cannot be null
)KeyValueBytesStoreSupplier
that can be used
to build a persistent storepublic static KeyValueBytesStoreSupplier inMemoryKeyValueStore(java.lang.String name)
KeyValueBytesStoreSupplier
.name
- name of the store (cannot be null
)KeyValueBytesStoreSupplier
than can be used to
build an in-memory storepublic static KeyValueBytesStoreSupplier lruMap(java.lang.String name, int maxCacheSize)
KeyValueBytesStoreSupplier
.name
- name of the store (cannot be null
)maxCacheSize
- maximum number of items in the LRU (cannot be negative)KeyValueBytesStoreSupplier
that can be used to build
an LRU Map based storepublic static WindowBytesStoreSupplier persistentWindowStore(java.lang.String name, long retentionPeriod, int numSegments, long windowSize, boolean retainDuplicates)
WindowBytesStoreSupplier
.name
- name of the store (cannot be null
)retentionPeriod
- length of time to retain data in the store (cannot be negative)numSegments
- number of db segments (cannot be zero or negative)windowSize
- size of the windows (cannot be negative)retainDuplicates
- whether or not to retain duplicates.WindowBytesStoreSupplier
public static SessionBytesStoreSupplier persistentSessionStore(java.lang.String name, long retentionPeriod)
SessionBytesStoreSupplier
.name
- name of the store (cannot be null
)retentionPeriod
- length ot time to retain data in the store (cannot be negative)SessionBytesStoreSupplier
public static <K,V> StoreBuilder<WindowStore<K,V>> windowStoreBuilder(WindowBytesStoreSupplier supplier, Serde<K> keySerde, Serde<V> valueSerde)
StoreBuilder
that can be used to build a WindowStore
.K
- key typeV
- value typesupplier
- a WindowBytesStoreSupplier
(cannot be null
)keySerde
- the key serde to usevalueSerde
- the value serde to use; if the serialized bytes is null for put operations,
it is treated as deleteStoreBuilder
than can build a WindowStore
public static <K,V> StoreBuilder<KeyValueStore<K,V>> keyValueStoreBuilder(KeyValueBytesStoreSupplier supplier, Serde<K> keySerde, Serde<V> valueSerde)
StoreBuilder
than can be used to build a KeyValueStore
.K
- key typeV
- value typesupplier
- a KeyValueBytesStoreSupplier
(cannot be null
)keySerde
- the key serde to usevalueSerde
- the value serde to use; if the serialized bytes is null for put operations,
it is treated as deleteStoreBuilder
that can build a KeyValueStore
public static <K,V> StoreBuilder<SessionStore<K,V>> sessionStoreBuilder(SessionBytesStoreSupplier supplier, Serde<K> keySerde, Serde<V> valueSerde)
StoreBuilder
that can be used to build a SessionStore
.K
- key typeV
- value typesupplier
- a SessionBytesStoreSupplier
(cannot be null
)keySerde
- the key serde to usevalueSerde
- the value serde to use; if the serialized bytes is null for put operations,
it is treated as deleteStoreBuilder
than can build a SessionStore
@Deprecated public static Stores.StoreFactory create(java.lang.String name)
persistentKeyValueStore(String)
, persistentWindowStore(String, long, int, long, boolean)
persistentSessionStore(String, long)
, lruMap(String, int)
, or inMemoryKeyValueStore(String)
StateStoreSupplier
instance.name
- the name of the store