简体   繁体   English

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

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

I'm having a problem with a combination of @EnableLoadTimeWeaving with AspectJ + @Transactional + @HystrixCommand . 我在将@EnableLoadTimeWeaving与AspectJ + @Transactional + @HystrixCommand结合使用时@EnableLoadTimeWeaving问题。

So, I've configured load-time weaving like this: 因此,我已经像这样配置了加载时编织:

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

plus instrumentation configuration. 加上仪器配置。

I have a bean A, annotated with @Transactional and method in it, annotated with @HystrixCommand . 我有一个用@Transactional和方法注释的bean A,用@HystrixCommand注释。

Then I have a bean B, also annotated with @Transactional , but having propagation = Propagation.MANDATORY , which means that it requires existing transaction and fails otherwise. 然后,我有一个bean B,也用@Transactional注释,但是具有propagation = Propagation.MANDATORY ,这意味着它需要现有事务,否则将失败。 There's also a method in this bean, annotated with @HystrixCommand . 这个bean中还有一个方法,用@HystrixCommand注释。

Eventually, when I call the method of bean B from the method of bean A, I get: No existing transaction found for transaction marked with propagation 'mandatory' . 最终,当我从bean A的方法调用bean B的方法时,我得到: No existing transaction found for transaction marked with propagation 'mandatory'

I was looking for the problem for a couple of hours: everything seems to be configured properly, so I almost gave up. 我一直在寻找问题几个小时:似乎一切都配置正确,所以我几乎放弃了。 And then I just tried to remove @HystrixCommand from methods. 然后我只是尝试从方法中删除@HystrixCommand And voilà: transaction propagation started to work properly and the exception was gone. 贴切:事务传播开始正常工作,并且异常消失了。

So I wonder: why does @HystrixCommand break transaction propagation? 所以我想知道:为什么@HystrixCommand中断事务传播? Is it somehow related to the fact that I'm using load-time weaving? 这与我使用加载时编织的事实有某种关系吗? Or is it expected behaviour? 还是预期的行为? Can someone shed some light on it? 有人可以阐明一下吗?

The problem you're stating is probably related to the fact that HystrixCommands are executed in an isolated thread : 您要说明的问题可能与HystrixCommands在独立线程中执行这一事实有关:

The default, and the recommended setting, is to run HystrixCommands using thread isolation (THREAD) and HystrixObservableCommands using semaphore isolation (SEMAPHORE). 默认值和建议的设置是使用线程隔离(THREAD)运行HystrixCommands,使用信号隔离(SEMAPHORE)运行HystrixObservableCommands。

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; 通常,只有在调用量如此之大(每个实例每秒数百个)以至于各个线程的开销过高时,才需要对HystrixCommands使用信号隔离。 this typically only applies to non-network calls. 这通常仅适用于非网络呼叫。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM