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) {         } }); 

see http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/transaction/support/transactionsynchronization.html


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -