JMS确认异步消息 [英] JMS Acknowledge Asynchronous Message

查看:139
本文介绍了JMS确认异步消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用消息监听器时如何确认消息?

How do I acknowledge a message when I am using a message listener?

当我尝试在消息侦听器中进行确认时,出现以下错误.

I get the following error when I try to do an acknowledge in my message listener.

A synchronous method call is not permitted when a session is being used asynchronously: 'acknowledge'

推荐答案

您在谈论JMS消息确认,如

You're talking about JMS messages acknowledgement as in Message.acknowledge()?

该错误似乎有点奇怪.如果您不使用事务处理或自动确认,那么我认为您需要调用该方法.而且,如果您要进行异步侦听,除了onMessage()方法之外,您还应该在哪里做呢?

That error seems a little odd. If you aren't using transactions or auto-acknowledge, I'd think you need to call that method. And if you're doing async listening, where are you doing to do it aside from the onMessage() method?

此调用是否在与onMessage()调用相同的线程中完成?换句话说,是在onMessage()还是从onMessage()调用的某些方法中?否则,您将违反JMS的线程规则.会话和生产者/消费者以及任何更深层次的内容(例如消息)都不是线程安全的.您需要确保没有从多个线程接触它们.如果您处于onMessage()调用的中间,并且以某种方式安排另一个线程来执行该Message.acknowledge()调用,则由于线程问题,您理应失败.如果是这样,则将该调用移回与运行onMessage()的线程相同的线程.

Is this call being done in the same thread that got the onMessage() call? In other words, in onMessage() or in some method called from onMessage()? If not, you're breaking the thread rules of JMS. Sessions and producers/consumers and anything further down (like Messages) aren't thread safe. You need to make sure you're not touching them from multiple threads. If you're in the middle of an onMessage() call and you somehow arrange another thread to do that Message.acknowledge() call, you deserve to fail because of the thread problem. If so, move that call back on the same thread that onMessage() is running in.

这篇关于JMS确认异步消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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