Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

aop - Hystrix command does not run in Hystrix environment

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...