如何使用spring的DefaultMessageListenerContainer进行手动提交?
我们有一个在队列上侦听消息的应用程序,我知道 dmlc 提供了一个 sessionTransacted 属性,我认为该属性允许我们手动提交消息接收事件,但是我不确定如何在侦听器中利用它。
看起来,只要抛出一个 RuntimeException,消息就会被放回到队列中,如果尚未设置 ErrorHandler 但我们想专门提交接收,则消息会进入循环。
例如
public class JMSMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
// do something with the message and then manually commit
}
}
We have an application that listens on a queue for messages and I know that the dmlc provides a sessionTransacted property that I assume would allow us to manually commit the message receive event, however I am not sure how to leverage it in the Listener.
It seems that simply by throwing a RuntimeException the message gets put back onto the queue and goes into a loop if an ErrorHandler has not been set but we would like to specifically commit the receive.
e.g.
public class JMSMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
// do something with the message and then manually commit
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有使用 ActiveMQ 的经验。启用
sessionTransacted
后,如果您的应用程序在onMessage
中意外关闭,消息将在重新启动后再次处理。如果会话没有被处理,它将丢失。您无法使用
sessionTransacted
手动控制事务(除了抛出异常以回滚消息)。您可能想看看 SessionAwareMessageListener,虽然我从来没有尝试过。A have an experience with ActiveMQ. When
sessionTransacted
is enabled, if your application shuts down unexpectedly inonMessage
, the message will be handled again after restart. If session is not transacted, it will be lost.You cannot manually control transaction (except throwing an exception to roll message back) using
sessionTransacted
. You might want to take a look at SessionAwareMessageListener, although I have never tried it.