Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Example use of onPartitionsAssigned#

Sumit Rawal answered on June 1, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Example use of onPartitionsRevoked#

  • Example use of onPartitionsAssigned#

    0

    Next, we’ll discuss an example of when it may make sense to use the onPartitionsAssigned method. Once a rebalance happens, the newly assigned consumer starts reading records from the stored offset. However, what if we want to skip ahead a few records or start reading from a few records back? Kafka allows us to start reading from either the beginning or the very end of a partition using the methods seekToBeginning(TopicPartition tp) and seekToEnd(TopicPartition tp) respectively. We can also position a consumer at a specific offset within a partition and have it read records starting from that offset. This may be required for applications working off of time-series data which may want to skip ahead a few records if they have become stale. More generally, if a consumer has lagged behind and the application can tolerate skipping messages, then it can jump over several of them and start reading more recent messages. The seek(TopicPartition tp, long offset) method available on the consumer object places the consumer at the passed-in offset for them to start reading from. Within the onPartitionsAssigned method, we can position the consumer at an offset of our choosing just before it starts processing records from that partition.

    Consider another scenario, say as you read records from the partition, you also write them into a database. The pseudocode within the poll loop will resemble something like the following:

    Popularity 1/10 Helpfulness 1/10 Language whatever
    Source: Grepper
    Tags: whatever
    Link to this answer
    Share Copy Link
    Contributed on Jun 01 2023
    Sumit Rawal
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.