Skip to content

Latest commit

 

History

History
65 lines (43 loc) · 2.15 KB

kafka-streams-Transformer.adoc

File metadata and controls

65 lines (43 loc) · 2.15 KB

Transformer — Record-by-Record Stateful Transformation

Transformer is the contract that allows for a stateful transformation of every record in the input stream into zero or more output records (both key and value type can be altered arbitrarily).

In order to emit (produce) no record, transform should simply return null.

In order to use a state, a state store has to be registered beforehand (using addStateStore or addGlobalStore) before they can be connected to the Transformer.

You can access a state store using the ProcessorContext that is given when a transformer is initialized.

Tip
You could emit more output records for a single record using the ProcessorContext and its forward method.
// FIXME: Demo

Transformer is created (supplied) using a corresponding TransformerSupplier.

Property Description

close

void close()

Closes the transformer

Used exclusively when KStreamTransformProcessor is requested to close

init

void init(final ProcessorContext context)

Initializes the transformer in the given ProcessorContext

Used exclusively when KStreamTransformProcessor is requested to initialize itself

transform

R transform(final K key, final V value)

Transforms a single record (into a KeyValue object)

In order to emit (produce) no record, transform should return null.

Used exclusively when KStreamTransformProcessor is requested to process a record

Transformer is used to create a KStreamTransformProcessor.