So far we have seen how offsets can be committed synchronously or asynchronously. In both cases, we commit the offset after all the returned records have been processed. If we were to return a large number of records, though, we may want to commit the offset midway or at a time of our choosing. Fortunately, both the APIs commitSync() and commitAsync() allow us to do just that by passing-in the offset for each partition of a topic that we want to commit. A sample snippet appears below:
So far we have seen how offsets can be committed synchronously or asynchronously. In both cases, we commit the offset after all the returned records have been processed. If we were to return a large number of records, though, we may want to commit the offset midway or at a time of our choosing. Fortunately, both the APIs commitSync() and commitAsync() allow us to do just that by passing-in the offset for each partition of a topic that we want to commit. A sample snippet appears below: