我第一次使用 Jboss 7.2 并试图部署一个简单的 MDB 。MDB 被注释为自动确认
@MessageDriven(activationConfig = {
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "/queue/test")
})
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
@TransactionManagement(value= TransactionManagementType.CONTAINER)
public class TextMessageListener implements MessageListener {
onMessage 很简单,只是睡觉和醒来。我的期望是一旦消息被 MDB 消费,即 onMessage 被调用,它应该从队列中删除。但是消息会一直保留在队列中,直到 onMessage 完成并且状态显示为“In Delivery”。
public void onMessage(Message message) {
System.out.println("sleeping for some time");
try {
Thread.sleep(10*60000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("awake and done now");
}
当 on-message 完成时,日志显示在完成后发送确认,因此在 onMessage 完成后从队列中删除消息。一些愚蠢的配置,因为它很简单。..但知道缺少什么。如何在 JBOSS 7.2 MDB 中设置自动确认,以便在调用 onMessage 后立即自动确认消息。
15:59:33,584 INFO [stdout] (Thread-3 (HornetQ-client-global-threads-467768789)) awake and done now
15:59:33,586 DEBUG [org.hornetq.core.client] (Thread-3 (HornetQ-client-global-threads-467768789)) client ack messageID = 1079
这是一件简单直接的事情,但它没有按预期工作。我们尝试使用消费者(一个独立的 java 测试客户端从队列中读取消息)并在那里工作。
一旦消息被消费者消费,即使消息正在由消费者处理但不在 MDB 中,它也会从队列中删除。
任何想法 ?
我曾尝试在 JBoss 社区提出同样的问题,但没有成功。希望有人会在这里回答..
提前致谢。