|
62 | 62 | import org.springframework.kafka.support.TopicPartitionInitialOffset.SeekPosition; |
63 | 63 | import org.springframework.kafka.support.TransactionSupport; |
64 | 64 | import org.springframework.kafka.transaction.KafkaTransactionManager; |
| 65 | +import org.springframework.lang.Nullable; |
65 | 66 | import org.springframework.scheduling.SchedulingAwareRunnable; |
66 | 67 | import org.springframework.scheduling.TaskScheduler; |
67 | 68 | import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; |
@@ -153,6 +154,7 @@ public void setClientIdSuffix(String clientIdSuffix) { |
153 | 154 | * @return the {@link TopicPartition}s currently assigned to this container, |
154 | 155 | * either explicitly or by Kafka; may be null if not assigned yet. |
155 | 156 | */ |
| 157 | + @Nullable |
156 | 158 | public Collection<TopicPartition> getAssignedPartitions() { |
157 | 159 | ListenerConsumer listenerConsumer = this.listenerConsumer; |
158 | 160 | if (listenerConsumer != null) { |
@@ -1258,17 +1260,19 @@ public void seekToEnd(String topic, int partition) { |
1258 | 1260 | this.seeks.add(new TopicPartitionInitialOffset(topic, partition, SeekPosition.END)); |
1259 | 1261 | } |
1260 | 1262 |
|
1261 | | - private void closeProducers(Collection<TopicPartition> partitions) { |
1262 | | - ProducerFactory<?, ?> producerFactory = this.kafkaTxManager.getProducerFactory(); |
1263 | | - partitions.forEach(tp -> { |
1264 | | - try { |
1265 | | - producerFactory.closeProducerFor(zombieFenceTxIdSuffix(tp.topic(), tp.partition())); |
1266 | | - } |
1267 | | - catch (Exception e) { |
1268 | | - this.logger.error("Failed to close producer with transaction id suffix: " |
1269 | | - + zombieFenceTxIdSuffix(tp.topic(), tp.partition()), e); |
1270 | | - } |
1271 | | - }); |
| 1263 | + private void closeProducers(@Nullable Collection<TopicPartition> partitions) { |
| 1264 | + if (partitions != null) { |
| 1265 | + ProducerFactory<?, ?> producerFactory = this.kafkaTxManager.getProducerFactory(); |
| 1266 | + partitions.forEach(tp -> { |
| 1267 | + try { |
| 1268 | + producerFactory.closeProducerFor(zombieFenceTxIdSuffix(tp.topic(), tp.partition())); |
| 1269 | + } |
| 1270 | + catch (Exception e) { |
| 1271 | + this.logger.error("Failed to close producer with transaction id suffix: " |
| 1272 | + + zombieFenceTxIdSuffix(tp.topic(), tp.partition()), e); |
| 1273 | + } |
| 1274 | + }); |
| 1275 | + } |
1272 | 1276 | } |
1273 | 1277 |
|
1274 | 1278 | private String zombieFenceTxIdSuffix(String topic, int partition) { |
|
0 commit comments