public class ByTopicRecordTranslator<K,V> extends Object implements RecordTranslator<K,V>
Based off of a given Kafka topic a ConsumerRecord came from it will be translated to a Storm tuple and emitted to a given stream.
DEFAULT_STREAM
Constructor and Description |
---|
ByTopicRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func,
Fields fields)
Create a simple record translator that will use func to extract the fields of the tuple, named by fields, and emit them to the default stream.
|
ByTopicRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func,
Fields fields,
String stream)
Create a simple record translator that will use func to extract the fields of the tuple, named by fields, and emit them to stream.
|
ByTopicRecordTranslator(RecordTranslator<K,V> defaultTranslator)
Create a record translator with the given default translator.
|
Modifier and Type | Method and 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.
|
ByTopicRecordTranslator<K,V> |
forTopic(String topic,
Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func,
Fields fields)
Configure a translator for a given topic with tuples to be emitted to the default stream.
|
ByTopicRecordTranslator<K,V> |
forTopic(String topic,
Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func,
Fields fields,
String stream)
Configure a translator for a given topic.
|
ByTopicRecordTranslator<K,V> |
forTopic(String topic,
RecordTranslator<K,V> translator)
Configure a translator for a given kafka topic.
|
Fields |
getFieldsFor(String stream)
Get the fields associated with a stream.
|
List<String> |
streams()
Get the list of streams this translator will handle.
|
public ByTopicRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields, String stream)
Create a simple record translator that will use func to extract the fields of the tuple, named by fields, and emit them to stream. This will handle all topics not explicitly set elsewhere.
func
- extracts and turns them into a list of objects to be emittedfields
- the names of the fields extractedstream
- the stream to emit these fields on.public ByTopicRecordTranslator(Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields)
Create a simple record translator that will use func to extract the fields of the tuple, named by fields, and emit them to the default stream. This will handle all topics not explicitly set elsewhere.
func
- extracts and turns them into a list of objects to be emittedfields
- the names of the fields extractedpublic ByTopicRecordTranslator(RecordTranslator<K,V> defaultTranslator)
Create a record translator with the given default translator.
defaultTranslator
- a translator that will be used for all topics not explicitly set with one of the variants of forTopic(java.lang.String, org.apache.storm.kafka.spout.RecordTranslator)
.public ByTopicRecordTranslator<K,V> forTopic(String topic, Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields)
Configure a translator for a given topic with tuples to be emitted to the default stream.
topic
- the topic this should be used forfunc
- extracts and turns them into a list of objects to be emittedfields
- the names of the fields extractedIllegalStateException
- if the topic is already registered to another translatorIllegalArgumentException
- if the Fields for the stream this emits to do not match any already configured Fields for the same streampublic ByTopicRecordTranslator<K,V> forTopic(String topic, Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>> func, Fields fields, String stream)
Configure a translator for a given topic.
topic
- the topic this should be used forfunc
- extracts and turns them into a list of objects to be emittedfields
- the names of the fields extractedstream
- the stream to emit the tuples to.IllegalStateException
- if the topic is already registered to another translatorIllegalArgumentException
- if the Fields for the stream this emits to do not match any already configured Fields for the same streampublic ByTopicRecordTranslator<K,V> forTopic(String topic, RecordTranslator<K,V> translator)
Configure a translator for a given kafka topic.
topic
- the topic this translator should handletranslator
- the translator itselfIllegalStateException
- if the topic is already registered to another translatorIllegalArgumentException
- if the Fields for the stream this emits to do not match any already configured Fields for the same streampublic List<Object> apply(org.apache.kafka.clients.consumer.ConsumerRecord<K,V> record)
RecordTranslator
Translate the ConsumerRecord into a list of objects that can be emitted.
apply
in interface Func<org.apache.kafka.clients.consumer.ConsumerRecord<K,V>,List<Object>>
apply
in interface RecordTranslator<K,V>
record
- the record to translateKafkaTuple
if you want to route the tuple to a non-default stream. Return null
to discard an invalid ConsumerRecord
if KafkaSpoutConfig.Builder.setEmitNullTuples(boolean)
is set to false
.public Fields getFieldsFor(String stream)
RecordTranslator
Get the fields associated with a stream. The streams passed in are returned by the RecordTranslator.streams()
method.
getFieldsFor
in interface RecordTranslator<K,V>
stream
- the stream the fields are forpublic List<String> streams()
RecordTranslator
Get the list of streams this translator will handle.
streams
in interface RecordTranslator<K,V>
Copyright © 2022 The Apache Software Foundation. All rights reserved.