Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.此内容没有您所选择的语言版本。
9.2. Demarcation by Marking the Route
Overview 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
If the consumer endpoint at the start of a route does not support transactions, you can nevertheless initiate a transaction immediately after receiving an incoming message by inserting the
transacted()
command into your route.
Demarcation using transacted() 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
By default, the
transacted()
command uses the first transaction manager of type PlatformTransactionManager
that it finds in the bean registry (which could either be an OSGi service, a bean defined in Spring XML, or a bean defined in blueprint). Because the PlatformTransactionManager
interface is, by default, exported as an OSGi service, the transacted()
command will automatically find the XA transaction manager.
When you use the
transacted()
command to mark a route as transacted, all of the processors following transacted()
participate in the transaction; all of the processors preceding transacted()
do not participate in the transaction. For example, you could use transacted()
to make a route transactional, as follows:
Important
If your container exports multiple OSGi services of
PlatformTransactionManager
type or if you register multiple TransactedPolicy
objects in the bean registry (for example, by defining beans in Spring XML), you cannot be certain which transaction manager would be picked up by the transacted()
command (see Default transaction manager and transacted policy). In such cases, it is recommended that you specify the transaction policy explicitly.
Specifying the transaction policy explicitly 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
To eliminate any ambiguity about which transaction manager is used, you can specify the transaction policy explicitly by passing the transaction policy's bean ID as an argument to the
transacted()
command. First of all, you need to define the transaction policy (of type, org.apache.camel.spring.spi.SpringTransactionPolicy
), which encapsulates a reference to the transaction manager you want to use—for example:
After the transaction policy bean is defined, you can use it by passing its bean ID,
XA_TX_REQUIRED
, as a string argument to the transacted()
command—for example:
For more details about transaction policies, see Propagation Policies.
XML syntax 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
You can also use the
transacted
command in Spring XML or blueprint files. For example, to demarcate an XA transaction in Spring XML: