public class Kafka08SimpleApiConsumer extends KafkaSimpleApiConsumer<String,ByteBuffer,Long>
KafkaSimpleApiConsumer compatible mode for Kafka 0.8.x releases.
The class expects these runtime arguments:
kafkaSource, SO_TIMEOUT| Constructor and Description |
|---|
Kafka08SimpleApiConsumer(KafkaSource kafkaSource) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configureKafka(KafkaConfigurer configurer)
Configure Kafka consumer.
|
void |
destroy()
Should be called for clean up.
|
protected Long |
getBeginOffset(org.apache.twill.kafka.client.TopicPartition topicPartition)
Returns the read offsets to start with for the given
TopicPartition. |
protected long |
getDefaultOffset(org.apache.twill.kafka.client.TopicPartition topicPartition)
Returns the default value of offset to start with when encounter a new broker for a given topic partition.
|
void |
initialize(co.cask.cdap.etl.api.realtime.RealtimeContext context)
The method should be called to initialized the consumer when being used by the
RealtimeSource |
protected void |
processMessage(ByteBuffer payload,
co.cask.cdap.etl.api.Emitter<co.cask.cdap.api.data.format.StructuredRecord> emitter)
Override this method if only interested in the payload of a message read from Kafka.
|
protected void |
processMessage(String key,
ByteBuffer payload,
co.cask.cdap.etl.api.Emitter<co.cask.cdap.api.data.format.StructuredRecord> emitter)
Override this method if interested in both the key and payload of a message read from Kafka.
|
protected Iterator<KafkaMessage<Long>> |
readMessages(KafkaConsumerInfo<Long> consumerInfo)
Read messages from Kafka.
|
protected void |
saveReadOffsets(Map<org.apache.twill.kafka.client.TopicPartition,Long> offsets)
Persists read offsets for all topic-partition that this Flowlet consumes from Kafka.
|
byteBufferToStructuredRecord, decodeKey, decodePayload, getKafkaConfig, getName, getOffsetStore, getSavedState, getStoreKey, pollMessages, processMessage, saveState, stopServicepublic Kafka08SimpleApiConsumer(KafkaSource kafkaSource)
protected void configureKafka(KafkaConfigurer configurer)
KafkaSimpleApiConsumerconfigureKafka in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>configurer - for configuring consuming from Kafkaprotected Iterator<KafkaMessage<Long>> readMessages(KafkaConsumerInfo<Long> consumerInfo) throws Exception
KafkaSimpleApiConsumerreadMessages in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>consumerInfo - Contains information about where to fetch messages fromIterator containing sequence of messages read from Kafka. The first message must
has offset no earlier than the KafkaConsumerInfo.getReadOffset() as given in the parameter.Exceptionpublic void initialize(co.cask.cdap.etl.api.realtime.RealtimeContext context)
throws Exception
KafkaSimpleApiConsumer
The method should be called to initialized the consumer when being used by the RealtimeSource
initialize in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>Exceptionpublic void destroy()
KafkaSimpleApiConsumerdestroy in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>protected void processMessage(String key, ByteBuffer payload, co.cask.cdap.etl.api.Emitter<co.cask.cdap.api.data.format.StructuredRecord> emitter)
KafkaSimpleApiConsumerprocessMessage in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>key - Key decoded from the messagepayload - Payload decoded from the messageemitter - The emitter to push the messageprotected void processMessage(ByteBuffer payload, co.cask.cdap.etl.api.Emitter<co.cask.cdap.api.data.format.StructuredRecord> emitter)
KafkaSimpleApiConsumerprocessMessage in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>payload - Payload decoded from the messageemitter - The emitter to push the messageprotected Long getBeginOffset(org.apache.twill.kafka.client.TopicPartition topicPartition)
KafkaSimpleApiConsumerTopicPartition.getBeginOffset in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>protected void saveReadOffsets(Map<org.apache.twill.kafka.client.TopicPartition,Long> offsets)
KafkaSimpleApiConsumersaveReadOffsets in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>protected long getDefaultOffset(org.apache.twill.kafka.client.TopicPartition topicPartition)
KafkaSimpleApiConsumerOffsetRequest.EarliestTime(). Sub-classes can override this to return
different value (for example OffsetRequest.LatestTime()).getDefaultOffset in class KafkaSimpleApiConsumer<String,ByteBuffer,Long>Copyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.