KafkaStreams
is the entry point for continuous record stream processing in Kafka Streams.
KafkaStreams
is "merely" a Kafka client that consumes messages from one or many Kafka source topics (known as SourceNodes) and publishes the processing results to zero, one or more Kafka target topics (known as SinkNodes).
Note
|
A Kafka Streams developer defines the processing logic either using a Topology directly (and define a DAG topology of Processors) or indirectly through a StreamsBuilder that provides the high-level DSL to define transformations. |
import org.apache.kafka.streams.KafkaStreams
val topology: Topology = ...
val config: StreamsConfig = ...
val ks = new KafkaStreams(topology, config)
Once created, you should start KafkaStreams
to start consuming, processing, and producing records (described in Topology).
ks.start()
Name | Description | ||
---|---|---|---|
|
|
||
|
Administrative client for Kafka, i.e. AdminClient, that supports managing and inspecting topics, brokers, configurations and ACLs.
|
||
|
|||
|
|||
|
|||
|
StreamsMetadataState (for the InternalTopologyBuilder and application.server configuration property) |
||
|
Stream processor threads (aka
|
Tip
|
Enable Add the following line to
Refer to Application Logging Using log4j. |
void cleanUp()
cleanUp
simply requests StateDirectory to clean when KafkaStreams
is not running.
cleanUp
reports a IllegalStateException
when KafkaStreams
is running.
Cannot clean up while running.
void close() // (1)
synchronized boolean close(final long timeout, final TimeUnit timeUnit)
-
Calls
close(final long timeout, final TimeUnit timeUnit)
with 0 timeout
close
…FIXME
Important
|
Always execute close on a KafkaStreams instance even if you never call start to avoid resource leaks.
|
Set<ThreadMetadata> localThreadsMetadata()
localThreadsMetadata
…FIXME
Note
|
localThreadsMetadata is used when…FIXME
|
// public API
KafkaStreams(
final Topology topology,
final Properties props) // (1)
KafkaStreams(
final Topology topology,
final StreamsConfig config) // (2)
// public API (mostly for testing)
KafkaStreams(
final Topology topology,
final StreamsConfig config,
final KafkaClientSupplier clientSupplier) // (3)
KafkaStreams(
final Topology topology,
final StreamsConfig config,
final Time time) // (4)
// private/internal API
KafkaStreams(
final InternalTopologyBuilder internalTopologyBuilder,
final StreamsConfig config,
final KafkaClientSupplier clientSupplier) // (5)
KafkaStreams(
final InternalTopologyBuilder internalTopologyBuilder,
final StreamsConfig config,
final KafkaClientSupplier clientSupplier,
final Time time) // (6)
-
Calls
KafkaStreams
(2) withStreamsConfig
with the inputprops
-
Calls
KafkaStreams
(3) withDefaultKafkaClientSupplier
-
Calls the internal
KafkaStreams
(6) withSystemTime
KafkaStreams
takes the following when created:
KafkaStreams
initializes the internal registries and counters.
boolean setRunningFromCreated()
setRunningFromCreated
…FIXME
Note
|
setRunningFromCreated is used exclusively when KafkaStreams is started.
|
String toString() // (1)
String toString(final String indent)
-
Calls
toString(final String indent)
with an empty indent, i.e.""
Note
|
toString with an indent is deprecated and should not be used. Use localThreadsMetadata instead.
|
toString
…FIXME
synchronized void start()
throws IllegalStateException, StreamsException
start
starts the Topology (that in turn starts consuming, processing, and producing records).
Internally, start
prints out the following DEBUG message to the logs:
Starting Streams client
start
marks KafkaStreams as running (i.e. transitions from CREATED to RUNNING state and notifies StateListeners).
start
starts global stream thread if defined (which is when…FIXME)
start
starts stream threads.
start
schedules a thread that requests StateDirectory to cleanRemovedTasks every state.cleanup.delay.ms milliseconds.
You should see the following DEBUG message in the logs:
Started Streams client
In case the changing state to running fails, start
merely prints out the following ERROR message to the logs:
Already stopped, cannot re-start
Collection<StreamsMetadata> allMetadataForStore(final String storeName)
allMetadataForStore
…FIXME
Note
|
allMetadataForStore is used when…FIXME
|