Fix close producers after a rebalance
With a transactional container if committing the offsets fails during a rebalance, we would leave the producers open. Move the close to a finally block. **cherry-pick to 2.0.x**
This commit is contained in:
committed by
Artem Bilan
parent
994fb29e16
commit
0bbb23a57f
@@ -472,19 +472,23 @@ public class KafkaMessageListenerContainer<K, V> extends AbstractMessageListener
|
||||
|
||||
@Override
|
||||
public void onPartitionsRevoked(Collection<TopicPartition> partitions) {
|
||||
if (this.consumerAwareListener != null) {
|
||||
this.consumerAwareListener.onPartitionsRevokedBeforeCommit(consumer, partitions);
|
||||
try {
|
||||
if (this.consumerAwareListener != null) {
|
||||
this.consumerAwareListener.onPartitionsRevokedBeforeCommit(consumer, partitions);
|
||||
}
|
||||
else {
|
||||
this.userListener.onPartitionsRevoked(partitions);
|
||||
}
|
||||
// Wait until now to commit, in case the user listener added acks
|
||||
commitPendingAcks();
|
||||
if (this.consumerAwareListener != null) {
|
||||
this.consumerAwareListener.onPartitionsRevokedAfterCommit(consumer, partitions);
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.userListener.onPartitionsRevoked(partitions);
|
||||
}
|
||||
// Wait until now to commit, in case the user listener added acks
|
||||
commitPendingAcks();
|
||||
if (this.consumerAwareListener != null) {
|
||||
this.consumerAwareListener.onPartitionsRevokedAfterCommit(consumer, partitions);
|
||||
}
|
||||
if (ListenerConsumer.this.kafkaTxManager != null) {
|
||||
closeProducers(partitions);
|
||||
finally {
|
||||
if (ListenerConsumer.this.kafkaTxManager != null) {
|
||||
closeProducers(partitions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user