我可以在单个 JMS 事务的上下文中接收消息、准备其响应并发送消息吗?

Can I receive a message, prepare its response and send a message in a context of a single JMS transaction?

在备考中我刚刚发现一个问题,我在网上查看后也无法回答。问题是:

"Can a server receive a request using a JMS message, prepare its response (e.g access a database) and send the reply using again, JMS, i the scope of a single JMS transaction?"

我知道我们可以在交易上下文中发送交易消息或接收消息。我知道我们可以将多个消息发送和接收分组在一个事务中,以保护整个交互。但是,JMS 被设计为异步的。所以理论上我需要有一个事务来将消息发送到队列和一个事务来从队列接收消息。我是对的还是可以对发送和接收进行单一交易?

是的,事务接收者可以在jMS中实现。它们是通过控制通信的确认模式来实现的:如果所有事务操作都成功,接收到的消息将被确认到代理,但在失败的情况下不会发生,因此可以重新传递消息。

This article 对此进行了更详细的解释:

Both message producers and message consumers may use transacted sessions. [...]

With message consumers, transacted sessions control message acknowledgment. The consumer can receive multiple messages just like the CLIENT_ACKNOWLEDGE mode. When the associated transaction is committed, the JMS implementation acknowledges all messages received in the associated transaction. If the transaction aborts, the JMS implementation returns the messages to the associated queue or topic.