简体   繁体   中英

How to handle transaction involving Spring message/JMS and Database

I have a method that get an invoice and it creates XML and send that XML to a JMS queue and then save the invoice to DB with updated status like 'invoiced'. Below is pseudo code that involves Spring and Hibernate. My question is: Is the failure in hibernate save rollsback Jms sending.or if JMS send failed, how can I roll back saving invoice status? is this comes under distributed transaction management. What are the transactional cases involved here. Thanks.

 @Transactional(propagation=Propagation.Required)    
 void processInvoices(invoice ){
           String xml = createXML(invoice);
           messageService.sendInvoice(xml );
           invoice.setStatus("invoiced");
           save(invoice);

  }

As per my knowledge and what I understand from your question you want to synchronize hibernate and JMS transaction, For doing this you will need to use JTA to manage transactions across the the both Hibernate and JMS

Read More @ Spring synchronising Hibernate and JMS transactions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM