简体   繁体   中英

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

I'm having a problem with a combination of @EnableLoadTimeWeaving with AspectJ + @Transactional + @HystrixCommand .

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 .

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. There's also a method in this bean, annotated with @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' .

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. And voilà: transaction propagation started to work properly and the exception was gone.

So I wonder: why does @HystrixCommand break transaction propagation? 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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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