简体   繁体   中英

How to support transaction/failover on jms?

At back end i want the atomic transactions which means that

try{
get database connection

update employee record;
update department record;
produces messages 1 on queue1
produces messages 2 on queue2
// some exception occured
}
finally{
connection.rollback();
// how to roll back the messages from queue
}

similarily if message broker is down how will i ensure , message is deilvered once it is up.

I am using ActiveMQ

Assuming you have a JmsSession to send the messages, you can do jmsSession.commit() and jmsSession.rollback() to complete the jms transaction.

If you want the messages to be persistent, ie they can be delivered after jms server crash, you can set the delivery mode of the message to be persistent: jmsMessageProducer.send(msg, DeliveryMode.PERSITENT)

See this for details:

http://docs.oracle.com/javaee/6/api/javax/jms/Session.html

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