alexkazan87 commented on code in PR #7454:
URL: https://github.com/apache/camel/pull/7454#discussion_r857909215
##########
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:
Correct! Generally, I would catch all the exceptions because "tomorrow"
Kafka client could throw a different exception and throw it as a specific camel
Kafka exception. So, you can handle and avoid the abort operation.
--
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]