Hystrix 命令不在 Hystrix 环境中运行 [英] Hystrix command does not run in Hystrix environment

查看:40
本文介绍了Hystrix 命令不在 Hystrix 环境中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Hystrix 命令有问题.如果对 hystrix 包装方法的调用来自类内部,则 hystrix 包装方法不会在 Hystrix 环境中运行

I am having an issue with my Hystrix commands. If the call to hystrix wrapped method comes from within the class, the hystrix-wrapped method does not run in Hystrix enviroment

在这种情况下,我将日志视为

In that case I see logs as

05-02-2018 22:51:25.809 [http-nio-auto-1-exec-3] INFO  c.i.q.v.e.ConnectorImpl.populateFIDSchema -
    populating FID Schema

但是,如果我从类外部调用相同的方法,我会看到它在 Hystrix 环境中运行

But, if I make call to the same method from outside the class, I see it running it in Hystrix enviroment

 05-02-2018 22:54:53.735 [hystrix-ConnectorImpl-1] INFO  c.i.q.v.e.ConnectorImpl.populateFIDSchema -
    populating FID Schema

我正在像这样用 HystrixCommand 包装我的方法

I am wrapping my method with HystrixCommand like this

 @HystrixCommand(commandKey = "getSchemaCommand", fallbackMethod = "getSchemaCommandFallback")

有什么想法吗?

推荐答案

与@pvpkiran 的回答相反,这不是 AspectJ 的限制,而是 Spring AOP 的限制.Spring AOP 是一种尝试通过代理实现 AspectJ 的子集的解决方案,而基于代理的方法是导致在未通过代理进行调用时不会调用通知的原因em>.

Contrary to @pvpkiran's answer, this is not a limitation of AspectJ, but a limitation Spring AOP. Spring AOP is a solution that tries to implement a subset of AspectJ through proxies, and the proxy based approach is what causing the advices not being called when the calls are not made through the proxy.

Spring AOP 功能和目标Spring 框架参考中的 AOP 代理 了解更多详情.

See Spring AOP capabilities and goals and AOP Proxies in the Spring Framework Reference for more details.

另一方面,AspectJ 直接修改了被通知类的字节码,完全不涉及代理,并且不受基于代理的 Spring AOP 的限制.

AspectJ on the other hand directly modifies the bytecode of the advised class, involves no proxies at all, and doesn't suffer from the limitation of the proxy based Spring AOP.

AspectJ 在几乎所有方面都优于 Spring AOP,因此我建议您从 Spring AOP 切换到 AspectJ(您不需要为此放弃 Spring,因为 Spring 和 AspectJ 可以很好地协同工作).

AspectJ is superior in pretty much all aspects to Spring AOP so I would advise you to switch over from Spring AOP to AspectJ (you don't need to ditch Spring for this as Spring and AspectJ can work together very well).

这篇关于Hystrix 命令不在 Hystrix 环境中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆