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

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

问题描述

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

在这种情况下,我看到的日志为

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环境中运行它

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

我用这样的HystrixCommand包装我的方法

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

有什么想法吗?

解决方案

与@pvpkiran的答案相反,这不是AspectJ的限制,而是Spring AOP的限制. Spring AOP是一种尝试通过代理来实现AspectJ的 subset 的解决方案,而基于代理的方法是当未通过代理进行调用时导致建议不被调用的原因.

请参见 Spring AOP功能和目标 AOP代理.

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

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

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

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

I am wrapping my method with HystrixCommand like this

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

Any ideas?

解决方案

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.

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

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 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天全站免登陆