开发者

What happens on a JMS queue when onMessage() throws a JMSException?

开发者 https://www.devze.com 2022-12-26 04:24 出处:网络
I\'m using Spring 2.5 with my custom class that implements MessageListener.If a JmsException is thrown in my onMessage( ) method, what happens to the state of the queue?

I'm using Spring 2.5 with my custom class that implements MessageListener. If a JmsException is thrown in my onMessage( ) method, what happens to the state of the queue?

Is the message considered "delivered" b开发者_运维百科y the queue the moment onMessage is called? Or does the JmsException trigger some kind of rollback and the message is re-entered on the queue?

Thanks in advance!


From the JMS 1.1 spec...

4.5.2 Asynchronous Delivery

A client can register an object that implements the JMS MessageListener interface with a MessageConsumer. As messages arrive for the consumer, the provider delivers them by calling the listener’s onMessage method.

It is possible for a listener to throw a RuntimeException; however, this is considered a client programming error. Well-behaved listeners should catch such exceptions and attempt to divert messages causing them to some form of application-specific ‘unprocessable message’ destination.

The result of a listener throwing a RuntimeException depends on the session’s acknowledgment mode.

  • AUTO_ACKNOWLEDGE or DUPS_OK_ACKNOWLEDGE - the message will be immediately redelivered. The number of times a JMS provider will redeliver the same message before giving up is provider-dependent. The JMSRedelivered message header field will be set for a message redelivered under these circumstances.
  • CLIENT_ACKNOWLEDGE - the next message for the listener is delivered. If a client wishes to have the previous unacknowledged message redelivered, it must manually recover the session.
  • Transacted Session - the next message for the listener is delivered. The client can either commit or roll back the session (in other words, a RuntimeException does not automatically rollback the session).

JMS providers should flag clients with message listeners that are throwing RuntimeExceptions as possibly malfunctioning.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号