Package org.apache.storm.kafka.spout
Class SimpleRecordTranslator<K,V>
- java.lang.Object
-
- org.apache.storm.kafka.spout.SimpleRecordTranslator<K,V>
-
- All Implemented Interfaces:
Serializable
,Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>>
,RecordTranslator<K,V>
public class SimpleRecordTranslator<K,V> extends Object implements RecordTranslator<K,V>
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface org.apache.storm.kafka.spout.RecordTranslator
DEFAULT_STREAM
-
-
Constructor Summary
Constructors Constructor Description SimpleRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields)
SimpleRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields, String stream)
Creates a SimpleRecordTranslator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Object>
apply(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
Translate the ConsumerRecord into a list of objects that can be emitted.Fields
getFieldsFor(String stream)
Get the fields associated with a stream.List<String>
streams()
Get the list of streams this translator will handle.
-
-
-
Constructor Detail
-
SimpleRecordTranslator
public SimpleRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields)
-
SimpleRecordTranslator
public SimpleRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields, String stream)
Creates a SimpleRecordTranslator.- Parameters:
func
- The mapping function responsible for translating a Kafka record to a Tuplefields
- The fields tuples constructed by this translator will containstream
- The stream tuples constructed by this translator will target
-
-
Method Detail
-
apply
public List<Object> apply(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
Description copied from interface:RecordTranslator
Translate the ConsumerRecord into a list of objects that can be emitted.- Specified by:
apply
in interfaceFunc<K,V>
- Specified by:
apply
in interfaceRecordTranslator<K,V>
- Parameters:
record
- the record to translate- Returns:
- the objects in the tuple. Return a
KafkaTuple
if you want to route the tuple to a non-default stream. Returnnull
to discard an invalidConsumerRecord
ifKafkaSpoutConfig.Builder.setEmitNullTuples(boolean)
is set tofalse
.
-
getFieldsFor
public Fields getFieldsFor(String stream)
Description copied from interface:RecordTranslator
Get the fields associated with a stream. The streams passed in are returned by theRecordTranslator.streams()
method.- Specified by:
getFieldsFor
in interfaceRecordTranslator<K,V>
- Parameters:
stream
- the stream the fields are for- Returns:
- the fields for that stream.
-
streams
public List<String> streams()
Description copied from interface:RecordTranslator
Get the list of streams this translator will handle.- Specified by:
streams
in interfaceRecordTranslator<K,V>
- Returns:
- the list of streams that this will handle.
-
-