加载时编织 (AspectJ):Hystrix 中断事务传播

Load-time weaving (AspectJ): Hystrix breaks transaction propagation

我在使用 @EnableLoadTimeWeaving 与 AspectJ + @Transactional + @HystrixCommand.

的组合时遇到问题

所以,我已经像这样配置了加载时编织:

@EnableLoadTimeWeaving(aspectjWeaving = ENABLED)
@EnableCaching(mode = AdviceMode.ASPECTJ)
@EnableTransactionManagement(mode = AdviceMode.ASPECTJ)

加仪器配置。

我有一个 bean A,用 @Transactional 注释,里面有方法,用 @HystrixCommand 注释。

然后我有一个 bean B,也用 @Transactional 注释,但有 propagation = Propagation.MANDATORY,这意味着它需要现有事务,否则失败。这个bean中还有一个方法,注解为@HystrixCommand.

最终,当我从 bean A 的方法调用 bean B 的方法时,我得到:No existing transaction found for transaction marked with propagation 'mandatory'.

我找了几个小时的问题:一切似乎都配置正确,所以我几乎放弃了。然后我只是尝试从方法中删除 @HystrixCommand 。瞧:事务传播开始正常工作,异常消失了。

所以我想知道:为什么 @HystrixCommand 中断事务传播?它与我使用加载时编织的事实有某种关系吗?还是预期的行为?有人可以解释一下吗?

您所说的问题可能与 HystrixCommands 在孤立的 thread:

中执行有关

The default, and the recommended setting, is to run HystrixCommands using thread isolation (THREAD) and HystrixObservableCommands using semaphore isolation (SEMAPHORE).

Commands executed in threads have an extra layer of protection against latencies beyond what network timeouts can offer.

Generally the only time you should use semaphore isolation for HystrixCommands is when the call is so high volume (hundreds per second, per instance) that the overhead of separate threads is too high; this typically only applies to non-network calls.