Please take a look at this example:
@Component
public class TransactionTest {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
private JmsTemplate jmsTemplate;
@Transactional
public void doTest() {
jdbcTemplate.execute("INSERT INTO some_table VALUES ('some_value')");
jmsTemplate.convertAndSend("some_queue", "some_value");
...
throw new SomeException();
}
...
}
For consistency purposes I want to perform both operations (inserting a database row and sending a JMS message) atomically so when SomeException will be raised then both operations will be rolled back (no new row will be in a database and no new JMS message will be in a queue).
Are there any mechanisms to handle this? I'm using Spring Framework, PostgreSQL, and Apache ActiveMQ for now.