public class KStreamBuilder extends TopologyBuilder
KStreamBuilder
is a subclass of TopologyBuilder
that provides the Kafka Streams DSL
for users to specify computational logic and translates the given logic to a org.apache.kafka.streams.processor.internals.ProcessorTopology
.TopologyBuilder.TopicsInfo
Constructor and Description |
---|
KStreamBuilder()
Create a new
KStreamBuilder instance. |
Modifier and Type | Method and Description |
---|---|
<K,V> KStream<K,V> |
merge(KStream<K,V>... streams)
Create a new instance of
KStream by merging the given streams. |
String |
newName(String prefix)
Create a unique processor name used for translation into the processor topology.
|
<K,V> KStream<K,V> |
stream(Pattern topicPattern)
Create a
KStream instance from the specified Pattern. |
<K,V> KStream<K,V> |
stream(Serde<K> keySerde,
Serde<V> valSerde,
Pattern topicPattern)
Create a
KStream instance from the specified Pattern. |
<K,V> KStream<K,V> |
stream(Serde<K> keySerde,
Serde<V> valSerde,
String... topics)
Create a
KStream instance from the specified topics. |
<K,V> KStream<K,V> |
stream(String... topics)
Create a
KStream instance from the specified topics. |
<K,V> KTable<K,V> |
table(Serde<K> keySerde,
Serde<V> valSerde,
String topic,
String storeName)
Create a
KTable instance for the specified topic. |
<K,V> KTable<K,V> |
table(String topic,
String storeName)
Create a
KTable instance for the specified topic. |
addInternalTopic, addProcessor, addSink, addSink, addSink, addSink, addSource, addSource, addSource, addSource, addStateStore, build, connectProcessorAndStateStores, connectProcessors, connectSourceStoreAndTopic, copartitionGroups, copartitionSources, nodeGroups, setApplicationId, sourceTopicPattern, sourceTopics, stateStoreNameToSourceTopics, topicGroups, updateSubscriptions
public KStreamBuilder()
KStreamBuilder
instance.public <K,V> KStream<K,V> stream(String... topics)
KStream
instance from the specified topics.
The default deserializers specified in the config are used.
If multiple topics are specified there are nor ordering guaranteed for records from different topics.
topics
- the topic names; must contain at least one topic nameKStream
for the specified topicspublic <K,V> KStream<K,V> stream(Pattern topicPattern)
KStream
instance from the specified Pattern.
The default deserializers specified in the config are used.
If multiple topics are matched by the specified pattern, the created stream will read data from all of them, and there is no ordering guarantee between records from different topics
topicPattern
- the Pattern to match for topic namesKStream
for topics matching the regex pattern.public <K,V> KStream<K,V> stream(Serde<K> keySerde, Serde<V> valSerde, String... topics)
KStream
instance from the specified topics.
If multiple topics are specified there are nor ordering guaranteed for records from different topics.
keySerde
- key serde used to read this source KStream
,
if not specified the default serde defined in the configs will be usedvalSerde
- value serde used to read this source KStream
,
if not specified the default serde defined in the configs will be usedtopics
- the topic names; must contain at least one topic nameKStream
for the specified topicspublic <K,V> KStream<K,V> stream(Serde<K> keySerde, Serde<V> valSerde, Pattern topicPattern)
KStream
instance from the specified Pattern.
If multiple topics are matched by the specified pattern, the created stream will read data from all of them, and there is no ordering guarantee between records from different topics.
keySerde
- key serde used to read this source KStream
,
if not specified the default serde defined in the configs will be usedvalSerde
- value serde used to read this source KStream
,
if not specified the default serde defined in the configs will be usedtopicPattern
- the Pattern to match for topic namesKStream
for the specified topicspublic <K,V> KTable<K,V> table(String topic, String storeName)
KTable
instance for the specified topic.
Record keys of the topic should never by null, otherwise an exception will be thrown at runtime.
The default deserializers specified in the config are used.
The resulting KTable
will be materialized in a local state store with the given store name.
However, no new changelog topic is created in this case since the underlying topic acts as one.topic
- the topic name; cannot be nullstoreName
- the state store name used if this KTable is materialized, can be null if materialization not expectedKTable
for the specified topicspublic <K,V> KTable<K,V> table(Serde<K> keySerde, Serde<V> valSerde, String topic, String storeName)
KTable
instance for the specified topic.
Record keys of the topic should never by null, otherwise an exception will be thrown at runtime.
The resulting KTable
will be materialized in a local state store with the given store name.
However, no new changelog topic is created in this case since the underlying topic acts as one.keySerde
- key serde used to send key-value pairs,
if not specified the default key serde defined in the configuration will be usedvalSerde
- value serde used to send key-value pairs,
if not specified the default value serde defined in the configuration will be usedtopic
- the topic name; cannot be nullstoreName
- the state store name used for the materialized KTableKTable
for the specified topicspublic <K,V> KStream<K,V> merge(KStream<K,V>... streams)
KStream
by merging the given streams.
There are nor ordering guaranteed for records from different streams.