JBoss 不发送 JmsTemplate (Spring) 消息

发布于 2024-07-25 07:50:44 字数 522 浏览 9 评论 0原文

好吧,实际上 JBoss 确实发送了消息,但仅当 EJB 启动的当前事务完成时才发送。

我们在 JBoss 4.0.3 和 Spring 的 JmsTemplate 中遇到了这个问题。 EJB 将消息发送到队列,并将临时队列作为reply_to 字段。 然后,在同一事务内,我们侦听第一个 MDB 给出的响应。 问题是 JmsTemplate 的方法“send”在事务完成后没有执行。 因此,当消息发送到队列并由 MDB 处理时,临时队列的侦听器已消失。

这称为“同步接收” 有

两件事改变了此行为,但确实引起了一些问题:

  1. 将 EJB 的事务类型更改为 BMT。 (关注:BMT 很糟糕)

  2. 创建一个线程,它所做的只是调用 JmsTemplate.send() 方法。

附带说明一下,这是一个在 weblogic 环境中正常工作的 EJB,并且消息确实在应该发送的时候发送,在事务中间而不是在事务结束时发送。

谢谢你的帮助。

Well, actually JBoss does send the message, but only when the current transaction started by the EJB is finished.

We have this problem with JBoss 4.0.3 and Spring's JmsTemplate. An EJB sends a message to a queue with a temporary queue as the reply_to field. Then, inside the same transaction, we listen for the response given by the first MDB. The problem is that the JmsTemplate's method "send" isn't executed after the transaction have finished. So, by the time the message is sent to the queue, and processed by the MDB, the listener of the temporary queue is gone.

This is called "Synchronous Reception"

Two things change this behavior but does raise some concerns:

  1. Change the EJB's transaction type to BMT. (Concern: BMT sucks)

  2. Create a thread that all it does is to call the JmsTemplate.send() method.

As a side note, this is an EJB that is working correctly on a weblogic environment, and the message does get sent when it should, in the middle of the transaction not when it's over.

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愿与i 2024-08-01 07:50:44

JBoss 的行为是正确的。 JMS 是一个事务性 API,只有在 tx 提交时才应执行发送。

也许可以说服 JmsTemplate 不使用当前的事务上下文,尽管它试图向您隐藏 JMS API 的不愉快之处。

JBoss's behaviour is correct. JMS is a transactional API, and sends should only be executed when the tx commits.

It may be possible to convince JmsTemplate not use the current transactional context, although it makes a point of trying to hide the unpleasantness of the JMS API from you.

鱼忆七猫命九 2024-08-01 07:50:44

您可以将 JMS 模板包装在代码中,可以是无状态会话 bean,也可以是使用 Spring 事务管理的服务方法,该方法使用 REQUIRES_NEW 的事务传播。 这样,消息的发送就在其自己的事务中,该事务将在包装事务的范围之外提交消息的发送。

我不确定为什么这会在 Weblogic 上工作。 我的猜测是,在 Weblogic 上它不会将队列识别为 XA 队列。

You could wrap the JMS template in code, either a Stateless session bean or a service method using Spring's transaction management, that uses a transaction propagation of REQUIRES_NEW. That way the sending of the message is in its own transaction that will commit the sending of the message outside the scope of the wrapping transaction.

I'm not sure why this would work on Weblogic though. My guess would be that on Weblogic it's not recognizing the queue as an XA Queue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文