【发布时间】:2019-03-30 15:57:09
【问题描述】:
我正在尝试在 Spring Boot 中的方法上使用 @Transactional 实现 hystrix。
@Transactional(transactionManager="primaryTrnsManager")
@HystrixCommand(commandKey ="createRecord", fallbackMethod="createRecordFallback", commandProperties={
@HystrixProperty(name="execution.siolation.thread.timeoutInMilliseconds",value="1000"),
@HystrixProperty(name="circuitBreaker.requestVoulumeThreshold",value="20"),
@HystrixProperty(name="circuitBreaker.sleepWindowInMilliseconds",value="5000"),
@HystrixProperty(name="circuitBreaker.errorThresholdPercentage",value="50")})
public String createRecord(String name){
...............
//Dbcall
}
@Transactional(transactionManager="backUptranManager",propagation=propagation.REQUIRES_NEW)
public String createRecordFallback(){
//dbcall
}
发生的事情是当 hystrix 超时发生时,我对数据库的调用没有回滚,hystrix 回退到辅助并再次使用相同的 sql 查询调用数据库。如果超时,我想中止前一个事务并开始另一个事务。通常@Transactional 会这样做,但使用 hystrix,我会插入重复的记录。
有什么帮助吗?
【问题讨论】:
标签: spring-boot timeout transactional hystrix