0

我们有一个javax.ejb.TimedObject像这样将消息排队到 MDB...

ctx = new InitialContext();
QueueConnectionFactory qCF = (QueueConnectionFactory) ctx
        .lookup("java:comp/env/jms/queueconnfactory");
Queue q = (Queue) ctx.lookup("java:comp/env/jms/queue");
conn = qCF.createQueueConnection();
session = conn.createQueueSession(true,
        Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(q);
TextMessage txtMsg = session.createTextMessage();
txtMsg.setLongProperty(JobMonitorUtil.JOB_REFERENCE_ID, filingId);
txtMsg.setLongProperty(JobMonitorUtil.JOB_ID, jobId);
txtMsg.setLongProperty(JobMonitorUtil.JOB_RUN_SID, jobRunSId);
sender.send(txtMsg);
session.close();
conn.close();

当我调试这个(在 Weblogic 10.3.1.0 上)时,我越过了 sender.sent(txtMsg) 行,我希望我的 onMessage 断点几乎立即被击中。直到我让 ejbTimeout 运行(实际上是当我退出 TimerImpl.timerExpired 时),它才达到我的断点。消息队列位于生成消息的同一台服务器上。

对我来说,这似乎很奇怪。

  • MDB 消息不是异步发送的吗?
  • 这可能是配置问题还是它应该如何工作?
4

1 回答 1

1

您创建了一个事务会话。在提交事务之前不会发送 JMS 消息(否则将无法回滚——消息已经到达远程系统)。

当您调用 session.close() 时事务被提交。

解决方案是(例如)创建一个非事务性会话:

session = conn.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
于 2011-04-18T23:44:17.313 回答