zhfeng commented on code in PR #7454:
URL: https://github.com/apache/camel/pull/7454#discussion_r858360125


##########
components/camel-kafka/src/main/java/org/apache/camel/component/kafka/KafkaProducer.java:
##########
@@ -492,4 +509,40 @@ private void doSend(Object key, ProducerRecord<Object, 
Object> record, KafkaProd
             kafkaProducer.send(record, cb);
         }
     }
+
+    private void startKafkaTransaction(Exchange exchange) {
+        exchange.getUnitOfWork().beginTransactedBy(transactionId);
+        kafkaProducer.beginTransaction();
+        exchange.getUnitOfWork().addSynchronization(new 
KafkaTransactionSynchronization(transactionId, kafkaProducer));
+    }
+}
+
+class KafkaTransactionSynchronization extends SynchronizationAdapter {
+    private static final Logger LOG = 
LoggerFactory.getLogger(KafkaTransactionSynchronization.class);
+    private String transactionId;
+    private Producer kafkaProducer;
+
+    public KafkaTransactionSynchronization(String transacionId, Producer 
kafkaProducer) {
+        this.transactionId = transacionId;
+        this.kafkaProducer = kafkaProducer;
+    }
+
+    @Override
+    public void onDone(Exchange exchange) {
+        try {
+            if (exchange.getException() != null || exchange.isRollbackOnly()) {

Review Comment:
   I make some changes to abort a transaction only when the exception is not 
```KafkaException```.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to