Skip to content

Commit 57e8021

Browse files
izeyegaryrussell
authored andcommitted
Polish KafkaTemplate.executeInTransaction()
1 parent 79c46c3 commit 57e8021

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

Diff for: spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java

+4-13
Original file line numberDiff line numberDiff line change
@@ -274,28 +274,19 @@ public <T> T executeInTransaction(OperationsCallback<K, V, T> callback) {
274274
}
275275

276276
this.producers.set(producer);
277-
T result = null;
278277
try {
279-
result = callback.doInOperations(this);
278+
T result = callback.doInOperations(this);
279+
producer.commitTransaction();
280+
return result;
280281
}
281282
catch (Exception e) {
282-
try {
283-
producer.abortTransaction();
284-
}
285-
finally {
286-
this.producers.remove();
287-
closeProducer(producer, false);
288-
}
283+
producer.abortTransaction();
289284
throw e;
290285
}
291-
try {
292-
producer.commitTransaction();
293-
}
294286
finally {
295287
this.producers.remove();
296288
closeProducer(producer, false);
297289
}
298-
return result;
299290
}
300291

301292
/**

0 commit comments

Comments
 (0)