spring jms 错误处理程序访问消息 [英] spring jms error handler access to message

查看:41
本文介绍了spring jms 错误处理程序访问消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 spring-jms 从队列中接收消息.但有时我们会遇到连接问题(侦听器线程上的下游 JDBC),其中池中没有足够的连接.所以我们想再次重试该消息,如果我们仍然没有连接,那么我们将拒绝该消息

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

我们正在错误处理程序中尝试此操作,并且该错误处理程序实例被注入到 spring 默认消息侦听器容器中,但我不确定如何访问消息对象,因为它仅提供 Throwable 对象.

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?

推荐答案

将消息传递给错误处理程序的唯一方法是在侦听器中捕获异常并将消息作为属性添加到新异常中(可能包装原因中的原始异常).

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.

如果您使用消息驱动的 POJO 而不是 MessageListener;您必须子类化 MessageListenerAdapter 并在 try/catch 块中调用 super.onMessage().

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.

无论如何,在回滚后调用 ErrorHandler,因此它无法改变该行为.

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

这篇关于spring jms 错误处理程序访问消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆