gpt4 book ai didi

java - 加载时编织 (AspectJ) : Hystrix breaks transaction propagation

转载 作者:行者123 更新时间:2023-11-30 01:48:02 27 4
gpt4 key购买 nike

我在使用 @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 的方法时,我得到:未找到标记为传播“强制”的事务的现有事务

我花了几个小时寻找问题:一切似乎都配置正确,所以我几乎放弃了。然后我尝试从方法中删除 @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.

关于java - 加载时编织 (AspectJ) : Hystrix breaks transaction propagation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57217248/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com