After going through Camel In Action book, I encountered following doubts.
I have below 2 routes
A.
from("file:/home/src") //(A.1) .transacted("required") //(A.2) .bean("dbReader", "readFromDB()") //(A.3) only read from DB .bean("dbReader", "readFromDB()") //(A.4) only read from DB .to("jms:queue:DEST_QUEUE") //(A.5)
Questions:
A.a. Is transacted in (A.2) really required here ?A.b. If answer to #a is yes, then what should be the associated transaction manager of the "required" policy ? Should it be JmsTransactionManager or JpaTransactionManager ?
A.c. As DEST_QUEUE is at the producer end, so does JMS component in (A.5) need to be transacted ?
B.
from("jms:queue:SRC_QUEUE") //(B.1) transactional jms endpoint .transacted("required") //(B.2) .bean("someBean", "someMethod()") //(B.3) simple arithmetic computation .to("jms1:queue:DEST_QUEUE") //(B.4)
SRC_QUEUE and DEST_QUEUE are queues of different jms broker
Questions:
B.a. The JMS component in (B.1) is marked as transacted, so in this case does route need to be transacted as mentioned in (B.2) ?
B.b. As DEST_QUEUE is at the producer end, so does JMS component in (B.4) need to be transacted ?
最佳答案
关于 Camel 事务处理的非常好的问题。
一般性评论:当谈论 Camel 事务时,它意味着使用从具有事务能力的系统(如数据库或 JMS 代理)进行的事务处理。路由中的 transacted
语句必须紧跟在 from
语句之后,因为它始终与消费相关。
A.a. Is transacted in (A.2) really required here ?
不,不是。由于文件系统不支持事务处理,因此它在这条路线上没有任何帮助。
A.b. If answer to #a is yes, then ... ?
没有“文件系统事务管理器”
A.c. As DEST_QUEUE is at the producer end, so does JMS component in (A.5) need to be transacted ?
不确定,但我不这么认为。生产者试图将消息传递给经纪人。 事务用于启用回滚,但是如果代理没有收到数据,回滚可以做什么?
B.a. The JMS component in (B.1) is marked as transacted, so in this case does route need to be transacted as mentioned in (B.2) ?
这取决于因为 SRC 和 DEST 在不同的代理上。
- 如果您想要代理之间的端到端交易,您需要使用 XA 交易管理器,然后您必须将路由标记为
已交易
。 - 如果您同意消费交易,您可以configure the JMS component for it并省略 Spring Tx 管理器和 Camel
transacted
语句。
澄清最后一点:如果您使用本地代理事务进行消费,Camel 在路由成功处理之前不会提交消息。因此,如果发生任何错误,将发生回滚并重新传递消息。
在大多数情况下,这完全没问题,但是,两个不同的代理仍然可能发生的情况是路由已成功处理,消息已传递到 DEST 代理,但 Camel 不再能够提交给 SRC 代理。然后发生重新投递,路由被再次处理并且消息被多次投递到 DEST 代理。
在我看来,XA 交易的复杂性比本地代理交易的非常罕见的边缘情况更难处理。但这是一个非常主观的意见,可能还取决于您使用的上下文或数据。
重要的是要注意:如果 SRC 和 DEST broker 相同,则本地 broker 事务 100% 足够! 绝对不需要 Spring Tx manager 和 Camel transacted
。
B.b. As DEST_QUEUE is at the producer end, so does JMS component in (B.4) need to be transacted ?
与 B.a. 的答案相同
关于apache-camel - Jms组件交易和 Camel 路线交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60247781/