Search code examples
aopaspectjhystrix

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?


Solution

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