Can KafkaTransactionManager usable with a ReactiveTransactionManager ? #2922
-
I have a project which use R2dbc and spring-kafka altogether. I want to commit the Kafka transaction after R2dbc transaction. Normally it can be achieved as documentation suggests : @Transactional("dstm")
public void someMethod(String in) {
this.kafkaTemplate.send("topic2", in.toUpperCase());
this.jdbcTemplate.execute("insert into mytable (data) values ('" + in + "')");
} But when using R2dbcTransactionManager, KafkaTemplate throws I guess KafkaTransactionManager uses ThreadLocal while ReactiveTransactionManager uses Reactor Context. So they do not know each other's transactions. How can i adapt the KafkaTransactionManager to use Reactor Context ? Should i completely rewrite it ? Thanks in advance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Right, the You may consider to use Rector Kafka instead: https://projectreactor.io/docs/kafka/release/reference/ |
Beta Was this translation helpful? Give feedback.
Right, the
KafkaTemplate
and itsKafkaProducer
are not Reactor-aware.Therefore you cannot use them with
ReactiveTransactionManager
.You may consider to use Rector Kafka instead: https://projectreactor.io/docs/kafka/release/reference/
6.9. Transactional send
.