2

We are using spring-jms to receive message off the queue. But sometimes we got a connection issue (downstream JDBC on the listener thread) where we don't have enough connection in the pool. So we want to retry that message again and if we still dont have connection then we will reject the message

We are trying this in error handler and that error handler instance is inject to spring default message listener container but I am not sure how to access the message object as it only provides Throwable object.

Does anyone know how to access actual message object?

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
user509755
  • 2,941
  • 10
  • 48
  • 82
  • Your question is not at all clear; if there's not an available connection, there can't be a message! – Gary Russell Oct 12 '15 at 17:16
  • we do see message came to receiver but when i say connection, i was talking about db connection. How can we handle a scenario where once message received and there is no db connection then we want to retry. – user509755 Oct 12 '15 at 17:56
  • I would like some way to know it too as I would like to log the message contents at least to see what message process failed. Sometimes exceptions happen outside the listener, so it is not possible to catch it there. – dabicho Apr 14 '16 at 21:38

1 Answers1

2

The only way to pass the message to the error handler is to catch the exception in your listener and add the message as a property to a new exception (probably wrapping the original exception in the cause).

You may find it simpler to just handle the exception in your user code.

If you are using message-driven POJOs instead of a MessageListener; you would have to subclass the MessageListenerAdapter and call super.onMessage() in a try/catch block.

EDIT:

In any case, the ErrorHandler is invoked after the rollback, so it can't change that behavior.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179