/** * Kafka will call this method whenever it is about to rebalance the * consumers for the given partitions. We'll simply take this to mean that * we need to quickly commit what we've got and will return the consumer to * the pool. This method will be called during the poll() method call of * this class and will be called by the same thread calling poll according * to the Kafka API docs. After this method executes the session and kafka * offsets are committed and this lease is closed. * * @param partitions partitions being reassigned */@Override
publicvoid onPartitionsRevoked(final Collection<TopicPartition> partitions) {
logger.debug("Rebalance Alert: Paritions '{}' revoked for lease '{}' with consumer '{}'", new Object[]{partitions, this, kafkaConsumer});
//force a commit here. Can reuse the session and consumer after this but must commit now to avoid duplicates if kafka reassigns partitioncommit();
}

/** * Abstract method that is intended to be extended by the pool that created * this ConsumerLease object. It should ensure that the session given to * create this session is rolled back and that the underlying kafka consumer * is either returned to the pool for continued use or destroyed if this * lease has been poisoned. It can only be called once. Calling it more than * once can result in undefined and non threadsafe behavior. */@Override
publicvoid close() {
resetInternalState();
}

/** * Abstract method that is intended to be extended by the pool that created * this ConsumerLease object. It should ensure that the session given to * create this session is rolled back and that the underlying kafka consumer * is either returned to the pool for continued use or destroyed if this * lease has been poisoned. It can only be called once. Calling it more than * once can result in undefined and non threadsafe behavior. */@Override
publicvoid close() {
resetInternalState();
}

Javadoc

This class represents a lease to access a Kafka Consumer object. The lease is
intended to be obtained from a ConsumerPool. The lease is closeable to allow
for the clean model of a try w/resources whereby non-exceptional cases mean
the lease will be returned to the pool for future use by others. A given
lease may only belong to a single thread a time.