[
https://issues.apache.org/jira/browse/TWILL-199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15803951#comment-15803951
]
ASF GitHub Bot commented on TWILL-199:
--------------------------------------
Github user maochf commented on a diff in the pull request:
https://github.com/apache/twill/pull/16#discussion_r94912977
--- Diff:
twill-core/src/main/java/org/apache/twill/kafka/client/KafkaConsumer.java ---
@@ -33,14 +33,16 @@
/**
* Invoked when new messages is available.
+ * @param startOffset Offset of the first {@link FetchedMessage} in
the iterator of new messages.
--- End diff --
Yes, I think one should be able to use `-1L` to fetch an upcoming new
message, which also aligns with the usage of `-1L` in Kafka's `SimpleConsumer`.
If the latest message is read, and it's the first message in the iterator, one
can just specify `startOffset` as the latest message offset if one doesn't want
to skip it. If the latest message is not the first message in the iterator and
its previous message was consumed, `onReceived` will still return the latest
message offset.
> Get next offset and handle offset error in KafkaConsumer.MessageCallback
> ------------------------------------------------------------------------
>
> Key: TWILL-199
> URL: https://issues.apache.org/jira/browse/TWILL-199
> Project: Apache Twill
> Issue Type: Improvement
> Reporter: Chengfeng Mao
>
> The method {{void onReceived(Iterator<FetchedMessage> messages)}} in
> {{KafkaConsumer.MessageCallback}} can be more flexible with the change to
> {{Long onReceived(Iterator<FetchedMessage> messages)}} so that it can provide
> additional functionalities:
> 1. To return the next offset to be fetched
> 2. To handle offset non-existence or offset mismatch error and take action on
> the error
> This method will return null for backward compatibility when it doesn't need
> to provide the next offset.
> In concrete implementation, a class of a new interface
> {{KafkaOffsetProvider}} can be added as a member in
> {{KafkaConsumer.MessageCallback}} to perform the offset error handling and
> provide the next offset. Besides, {{KafkaOffsetProvider}} also has methods to
> provide the following functionalities:
> 1. To fetch earliest/latest offset in Kafka
> 2. To find the offset of a message with timestamp equal to the given
> timestamp in Kafka
> For backward compatibility, if {{KafkaOffsetProvider}} instance is not
> provided, its default value will be null and none of its methods will be
> called.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)