KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've been working with JMS and ActiveMQ. Everything is working wonders. I am not using spring, nor can I. The interface javax.jms.MessageListener has only one method, onMessage . From within a implementation, there is a chance an exception will be thrown. If in fact an exception gets thrown, then I say the message wasn't properly processed and needs to be re-tried. So, I need ActiveMQ to wait for a little while and then, retry. i.e. I need the thrown exception to rollback the JMS transaction. How can I accomplish such a behaviour? Maybe there is some configuration in ActiveMQ I wasn't able to find. Or... maybe could do away with registering MessageListener s to consumers and consume the messages myself, in a a loop like: while (true) { // ... some administrative stuff like ... session = connection.createSesstion(true, SESSION_TRANSACTED) try { Message m = receiver.receive(queue, 1000L); theMessageListener.onMessage(m); session.commit(); } catch (Exception e) { session.rollback(); Thread.sleep(someTimeDefinedSomewhereElse); } // ... some more administrative stuff } in a couple of threads, instead of registering the listener. Or... I could somehow decorate/AOP/byte-manipulate the MessageListener s to do this themselves. What route would you take and why? note : I don't have full control over the MessageListener s code. EDIT A test for proof of concept: @Test @Ignore("Interactive test, just a proof of concept") public void transaccionConListener() throws Exception { final AtomicInteger atomicInteger = new AtomicInteger(0); BrokerService brokerService = new BrokerService(); String bindAddress = "vm://localhost"; brokerService.addConnector(bindAddress); brokerService.set
Tags (comma-separated)
Save Edits
Cancel