K - the key of the incoming RecordsV - the value of the incoming Recordspublic class ByTopicRecordTranslator<K,V> extends Object implements RecordTranslator<K,V>
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)
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)
func - extracts and turns them into a list of objects to be emittedfields - the names of the fields extractedpublic ByTopicRecordTranslator(RecordTranslator<K,V> defaultTranslator)
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)
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)
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)
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)
RecordTranslatorapply 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)
RecordTranslatorRecordTranslator.streams() method.getFieldsFor in interface RecordTranslator<K,V>stream - the stream the fields are forpublic List<String> streams()
RecordTranslatorstreams in interface RecordTranslator<K,V>Copyright © 2023 The Apache Software Foundation. All rights reserved.