spring jms error handler access to message

 ̄綄美尐妖づ 提交于 2019-12-10 22:49:05

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/33085662/spring-jms-error-handler-access-to-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!