MDB onMessage 在 ejbTimeout 结束之前不会开始。难道不应该异步启动吗?
我们有一个 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消息不是异步发送的吗?
- 这可能是配置问题还是它应该如何工作?
We have a javax.ejb.TimedObject which queues messages to an MDB like so...
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();
When I debug this (on Weblogic 10.3.1.0) I step over the sender.sent(txtMsg) line and I expect my onMessage breakpoint to be hit almost instantaneously. It doesn't hit my breakpoint until I let the ejbTimeout run (actually when I step out of TimerImpl.timerExpired). The message queue is on the same server which generates the messages.
To me it seems odd.
- Aren't MDB messages sent asyncronously?
- Could this be a configuration problem or is this how it's supposed to work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您创建了一个事务会话。在事务提交之前,JMS 消息不会发送出去(否则无法回滚——消息已经到达远程系统)。
当您调用 session.close() 时,事务将被提交。
解决方案是(例如)创建一个非事务性会话:
You created a transactional session. JMS messages are not sent out until transaction is committed (otherwise rollback wouldn't be possible -- message has reached the remote system already).
The transaction is committed when you call session.close().
Solution would be (for example) to create a non-transactional session: