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?
This is a limitation of Spring AOP (Hystrix-Javanica is based on AOP).
When you call a method locally, it doesn't go through a proxy and hence it doesn't really run in Hystrix environment, instead it runs as if it's another method.
But when you make a call from outside the class, it goes through proxy and hence it works.
This is true of many other functionalities. Another example is
@Cacheable
When you call from outside the class, Hystrix (Spring AOP) intercepts the call and wraps it around its own environment. But when you do a call locally, it cannot intercept the call.
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).