0
votes

As we known, if there is any exception is thrown at onMessage method of MessageListener, the JMS will try to consume that message again, which called "Redelivery".

But what I'm curious is how did it implement this feature? How did onMessage methods know if there is any exception is thrown? I know the answer may be a basic java knowledge. But unfortunately, I still have no idea on it.

So... is there anyone can clarify it?

1
You might want to check out OpenJMS, an open-source implementation of the JMS spec: sourceforge.net/projects/openjms - derekerdmann
thanks, that's very helpful! - Xianyi Ye

1 Answers

1
votes

This is specific to a particular JMS provider. But if your onMessage() method throws an exception, the code of the JMS provider that calls your onMessage() can just catch it, .e.g

try {
   listener.onMessage(..);
} catch (Exception ex) {
   //handle exception
}

And if an exception is caught, it can employ a strategy for redelivering the message. The client could send a message back to the JMS broker telling the broker that message delivery failed, and let the broker re-deliver that message.