Apache Camel 3.7.3 和 transaced() 隔离
Apache Camel 3.7.3 and transaced() isolation
假设我有一条路线
import org.apache.camel.builder.RouteBuilder;
class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("file:src/data?noop=true")
.transacted()
.bean("accountService","credit")
.bean("accountService","debit");
}
}
如你所见,我正在使用 transacted(),我知道如何选择事务传播策略,即
REQUIRED_NEW
、PROPAGATION_MANDATORY
等
但是,我不知道如何更改 transacted() 隔离级别,即如何设置它
到隔离级别 SERIALIZABLE
?
备注:
我正在使用
JAVA 11
SpringBoot 2.4.5
Apache Camel 3.7.3
transacted 方法可以引用持有希望的事务策略的特定 bean:
.transacted("PROPAGATION_REQUIRED")
或者,如果是 SpringRouteBuilder
,您可以使用 Policy
个对象:
public void configure() {
Policy myPolicy = bean(SpringTransactionPolicy.class, "PROPAGATION_REQUIRES_NEW"));
...
from("...")
.policy(myPolicy)
如果您想使用自定义隔离级别,我认为您必须创建一个 SpringTransactionPolicy
并提供一个 TransactionTemplate
实例:请参阅 here
这样做,您将能够specify 想要的隔离级别:
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
SpringTransactionPolicy customPolicy = new SpringTransactionPolicy(transactionTemplate);
from("...")
.policy(customPolicy)
假设我有一条路线
import org.apache.camel.builder.RouteBuilder;
class MyRouteBuilder extends RouteBuilder {
public void configure() {
from("file:src/data?noop=true")
.transacted()
.bean("accountService","credit")
.bean("accountService","debit");
}
}
如你所见,我正在使用 transacted(),我知道如何选择事务传播策略,即
REQUIRED_NEW
、PROPAGATION_MANDATORY
等
但是,我不知道如何更改 transacted() 隔离级别,即如何设置它
到隔离级别 SERIALIZABLE
?
备注:
我正在使用
JAVA 11
SpringBoot 2.4.5
Apache Camel 3.7.3
transacted 方法可以引用持有希望的事务策略的特定 bean:
.transacted("PROPAGATION_REQUIRED")
或者,如果是 SpringRouteBuilder
,您可以使用 Policy
个对象:
public void configure() {
Policy myPolicy = bean(SpringTransactionPolicy.class, "PROPAGATION_REQUIRES_NEW"));
...
from("...")
.policy(myPolicy)
如果您想使用自定义隔离级别,我认为您必须创建一个 SpringTransactionPolicy
并提供一个 TransactionTemplate
实例:请参阅 here
这样做,您将能够specify 想要的隔离级别:
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
transactionTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ);
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
SpringTransactionPolicy customPolicy = new SpringTransactionPolicy(transactionTemplate);
from("...")
.policy(customPolicy)