spring-cloud-stream producer transactionality -
i've done little testing kafka binder , appears spring-cloud-stream producers don't participate in spring-managed transactions.
given code
@requestmapping(method = requestmethod.post) @transactional public customer insertcustomer(@requestbody customer customer) { customerdao.insertcustomer(customer); source.output().send(messagebuilder.withpayload(customereventhelper.createsaveevent(customer)).build()); if (true) { throw new runtimeexception("rollback test"); } return customer; }
the customerdao.insertcustomer call rolled back, kafka message still sent. if have consumer on customer event inserts customer data warehouse, data warehouse , system of record out of synch on transation rollback. there way make kafka binder transactional here?
the kafka binder not transactional, , kafka not support transactions in general.
we intend address transaction management spring cloud stream 1.1: https://github.com/spring-cloud/spring-cloud-stream/issues/536.
however, can send messages after successful commit registering transaction synchronization this:
transactionsynchronizationmanager.registersynchronization( new transactionsynchronization(){ void aftercommit(){ source.output().send(messagebuilder.withpayload(event).build()); if (true) { } });
Comments
Post a Comment