0
votes

I am trying to integrate Hystrix javanica into my existing java EJB web application and facing 2 issues with running it.

  1. When I try to invoke following service it always returns response from fallback method and I see that the Throwable object in fallback method has "com.netflix.hystrix.exception.HystrixTimeoutException" exception.

  2. Each time this service is triggered, HystrixCommad and fallback methods are called multiple times around 50 times.

Can anyone suggest me with any inputs? Am I missing any configuration?

I am including following libraries in my project. project libraries

I have setup my aspect file as follows:

<aspectj>
 <weaver options="-verbose -showWeaveInfo"></weaver>
 <aspects>
    <aspect name="com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect"/>
 </aspects>
</aspectj>

Here is my config.properties file in META-INF/config.properties

hystrix.command.default.execution.timeout.enabled=false

Here is my rest service file

@Path("/hystrix")
public class HystrixService {

 @GET
 @Path("clusterName")
 @Produces({ MediaType.APPLICATION_JSON })
 public Response getClusterName(@QueryParam("id") int id) {
    ClusterCmdBean clusterCmdBean = new ClusterCmdBean();
    String result = clusterCmdBean.getClusterNameForId(id);
    return Response.ok(result).build();
 }
}

Here is my bean class

public class ClusterCmdBean {

 @HystrixCommand(groupKey = "ClusterCmdBeanGroup", commandKey = "getClusterNameForId", fallbackMethod = "defaultClusterName")
 public String getClusterNameForId(int id) {
    if (id > 0) {
        return "cluster"+id;
    } else {
        throw new RuntimeException("command failed");
    }
 }

 public String defaultClusterName(int id, Throwable e) {
    return "No cluster - returned from fallback:" + e.getMessage();
 }
}

Thanks for the help.

1

1 Answers

0
votes

If you want to ensure you are setting the property, you can do that explicitly in the circuit annotation itself:

@HystrixCommand(commandProperties = {
    @HystrixProperty(name = "execution.timeout.enabled", value = "false")
})

I would only recommend this for debugging purposes though.

Something that jumps out to me is that Javanica uses AspectJ AOP, which I have never seen work with new MyBean() before. I've always have to use @Autowired with Spring or similar to allow proxying. This could well just be something that is new to me though. If you set a breakpoint inside the getClusterNameForId can you see in the stack trace that its being called via reflection (which it should be AFAIK)?

Note you can remove commandKey as this will default to the method name. Personally I would also remove groupKey and let it default to the class name.