- Type Parameters:
K- key type
V- value type
KeyValuereturn type (both key and value type can be set arbitrarily)
public interface Transformer<K,V,R>The
Transformerinterface is for stateful mapping of an input record to zero, one, or multiple new output records (both key and value type can be altered arbitrarily). This is a stateful record-by-record operation, i.e,
transform(Object, Object)is invoked individually for each record of a stream and can access and modify a state that is available beyond a single call of
KeyValueMapperfor stateless record transformation). Additionally, this
schedulea method to be
called periodicallywith the provided context.
TransformerSupplierto provide new instances of
Transformerto Kafka Stream's runtime.
If only a record's value should be modified
ValueTransformercan be used.
All Methods Instance Methods Abstract Methods Modifier and Type Method Description
close()Close this transformer and clean up any resources.
init(ProcessorContext context)Initialize this transformer.
transform(K key, V value)Transform the record with the given key and value.
void init(ProcessorContext context)Initialize this transformer. This is called once per instance when the topology gets initialized. When the framework is done with the transformer,
close()will be called on it; the framework may later re-use the transformer by calling
context- the context
transformTransform the record with the given key and value. Additionally, any
attachedto this operator can be accessed and modified arbitrarily (cf.
If only one record should be forward downstream,
transformcan return a new
KeyValue. If more than one output record should be forwarded downstream,
ProcessorContext.forward(Object, Object, To)can be used. If no record should be forwarded downstream,
null. Note that returning a new
KeyValueis merely for convenience. The same can be achieved by using
ProcessorContext.forward(Object, Object)and returning
key- the key for the record
value- the value for the record
nullno key-value pair will be forwarded to down stream