|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectco.cask.cdap.api.flow.flowlet.AbstractFlowlet
co.cask.cdap.kafka.flow.KafkaConsumerFlowlet<KEY,PAYLOAD,OFFSET>
KEY - Type of message keyPAYLOAD - Type of message valueOFFSET - Type of offset objectpublic abstract class KafkaConsumerFlowlet<KEY,PAYLOAD,OFFSET>
Abstract base class for implementing consuming data from a Kafka cluster. This class serves as the generic base to help in implementing a flowlet that can poll from a specific Kafka version. Users should be extending from one of the sub-classes of this class.
| Field Summary | |
|---|---|
protected static int |
SO_TIMEOUT
|
| Constructor Summary | |
|---|---|
KafkaConsumerFlowlet()
|
|
| Method Summary | |
|---|---|
protected abstract void |
configureKafka(KafkaConfigurer configurer)
Configure Kafka consumer. |
protected KEY |
decodeKey(ByteBuffer buffer)
Override this method to provide custom decoding of a message key. |
protected PAYLOAD |
decodePayload(ByteBuffer buffer)
Override this method to provide custom decoding of a message payload. |
protected abstract OFFSET |
getBeginOffset(org.apache.twill.kafka.client.TopicPartition topicPartition)
Returns the read offsets to start with for the given TopicPartition. |
protected KafkaConfig |
getKafkaConfig()
Returns a Kafka configuration. |
protected co.cask.cdap.api.dataset.lib.KeyValueTable |
getOffsetStore()
Override to return a KeyValueTable for storing consumer offsets. |
protected String |
getStoreKey(org.apache.twill.kafka.client.TopicPartition topicPartition)
Returns the key to be used when persisting offsets into a KeyValueTable. |
protected void |
handleInstancesChanged(KafkaConsumerConfigurer configurer)
Override to handle changes in flowlet instances. |
void |
initialize(co.cask.cdap.api.flow.flowlet.FlowletContext context)
Initialize this Flowlet. |
co.cask.cdap.api.flow.flowlet.FailurePolicy |
onFailure(Object input,
co.cask.cdap.api.flow.flowlet.InputContext inputContext,
co.cask.cdap.api.flow.flowlet.FailureReason reason)
|
void |
onSuccess(Object input,
co.cask.cdap.api.flow.flowlet.InputContext inputContext)
|
void |
pollMessages()
A Tick method that triggered periodically by the Flow system to poll messages from Kafka. |
protected void |
processMessage(KafkaMessage<OFFSET> message)
Overrides this method if interested in the raw Kafka message. |
protected void |
processMessage(KEY key,
PAYLOAD payload)
Override this method if interested in both the key and payload of a message read from Kafka. |
protected void |
processMessage(PAYLOAD payload)
Override this method if only interested in the payload of a message read from Kafka. |
protected abstract Iterator<KafkaMessage<OFFSET>> |
readMessages(KafkaConsumerInfo<OFFSET> consumerInfo)
Read messages from Kafka. |
protected abstract void |
saveReadOffsets(Map<org.apache.twill.kafka.client.TopicPartition,OFFSET> offsets)
Persists read offsets for all topic-partition that this Flowlet consumes from Kafka. |
protected void |
stopService(com.google.common.util.concurrent.Service service)
Stops a Service and waits for the completion. |
| Methods inherited from class co.cask.cdap.api.flow.flowlet.AbstractFlowlet |
|---|
configure, destroy, getContext, getDescription, getName |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final int SO_TIMEOUT
| Constructor Detail |
|---|
public KafkaConsumerFlowlet()
| Method Detail |
|---|
public void initialize(co.cask.cdap.api.flow.flowlet.FlowletContext context)
throws Exception
Flowlet. Child class must call this method explicitly when overriding it.
initialize in interface co.cask.cdap.api.flow.flowlet.Flowletinitialize in interface co.cask.cdap.api.ProgramLifecycle<co.cask.cdap.api.flow.flowlet.FlowletContext>initialize in class co.cask.cdap.api.flow.flowlet.AbstractFlowletException
public void pollMessages()
throws Exception
Tick method that triggered periodically by the Flow system to poll messages from Kafka.
The default poll delay is 100 milliseconds. This method can be overridden to provide different delay value.
@Override
@Tick(delay = 1, unit = TimeUnit.SECONDS)
public void pollMessages() {
super.pollMessages();
}
Exception
public void onSuccess(Object input,
co.cask.cdap.api.flow.flowlet.InputContext inputContext)
onSuccess in interface co.cask.cdap.api.flow.flowlet.CallbackonSuccess in class co.cask.cdap.api.flow.flowlet.AbstractFlowlet
public co.cask.cdap.api.flow.flowlet.FailurePolicy onFailure(Object input,
co.cask.cdap.api.flow.flowlet.InputContext inputContext,
co.cask.cdap.api.flow.flowlet.FailureReason reason)
onFailure in interface co.cask.cdap.api.flow.flowlet.CallbackonFailure in class co.cask.cdap.api.flow.flowlet.AbstractFlowletprotected co.cask.cdap.api.dataset.lib.KeyValueTable getOffsetStore()
KeyValueTable for storing consumer offsets.
protected abstract void configureKafka(KafkaConfigurer configurer)
initialize(FlowletContext) phase,
hence it has access to FlowletContext through the AbstractFlowlet.getContext() method.
configurer - for configuring consuming from Kafkaprotected abstract Iterator<KafkaMessage<OFFSET>> readMessages(KafkaConsumerInfo<OFFSET> consumerInfo)
consumerInfo - Contains information about where to fetch messages from
Iterator containing sequence of messages read from Kafka. The first message must
has offset no earlier than the KafkaConsumerInfo.getReadOffset() as given in the parameter.protected abstract OFFSET getBeginOffset(org.apache.twill.kafka.client.TopicPartition topicPartition)
TopicPartition.
protected abstract void saveReadOffsets(Map<org.apache.twill.kafka.client.TopicPartition,OFFSET> offsets)
protected void handleInstancesChanged(KafkaConsumerConfigurer configurer)
configurer - for configuring consuming from Kafkaprotected final KafkaConfig getKafkaConfig()
protected void processMessage(KafkaMessage<OFFSET> message)
throws Exception
message - The message fetched from Kafka.
Exception
protected void processMessage(KEY key,
PAYLOAD payload)
throws Exception
key - Key decoded from the messagepayload - Payload decoded from the message
Exception
protected void processMessage(PAYLOAD payload)
throws Exception
payload - Payload decoded from the message
Exceptionprotected KEY decodeKey(ByteBuffer buffer)
buffer - The bytes representing the key in the Kafka message
protected PAYLOAD decodePayload(ByteBuffer buffer)
buffer - The bytes representing the payload in the Kafka message
protected final void stopService(com.google.common.util.concurrent.Service service)
Service and waits for the completion. If there is exception during stop, it will get logged.
protected String getStoreKey(org.apache.twill.kafka.client.TopicPartition topicPartition)
KeyValueTable.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||