1 Reply Latest reply on Oct 5, 2017 7:20 AM by turbotrakt0r

    HystrixCommand and Weld

    clueless248

      Hi @all,

       

      since yesterday I observed a strange behaviour with HystrixCommand and Wildfly 10 (Weld).

       

      First we create a Bean with CDI injection:

       

      @Stateless
      @Remote
      public class Bean implements BeanInterface {
      @Inject
      private Adapter adapter;

      @Override
      public Result getDebitData(Request request) {
      return adapter.getDebitData(request);
      }
      }

       

      The adapter communicates to a REST server and is protected by a Hysterix command.

       

      public class Adapter {
      @Inject
      private RestConnector connector;

      @HystrixCommand
      @Interceptors({ HystrixInterceptor.class })
      public Result getDebitData(Request request) {
      Response clientResponse = connector.connect().getDebitData(request);
      checkHttpStatusCodeWasSuccess(clientResponse);
      return clientResponse.readEntity(Result .class);
      }

      }

       

      If we now let run our integration test case I observe a strange behaviour. The method getDebitData is not executed once it is executed many times. A breakpoint inside Adapter.getDebitData will be never reached.

       

      The log file log like this:

       

      2017-09-27 15:32:41,971 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-6) execute command: getDebitData
      2017-09-27 15:32:41,971 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-9) execute command: getDebitData
      2017-09-27 15:32:41,972 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-1) execute command: getDebitData
      2017-09-27 15:32:41,974 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-8) execute command: getDebitData
      2017-09-27 15:32:41,974 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-10) execute command: getDebitData
      2017-09-27 15:32:41,974 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-2) execute command: getDebitData
      2017-09-27 15:32:41,975 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-3) execute command: getDebitData
      2017-09-27 15:32:41,975 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-5) execute command: getDebitData
      2017-09-27 15:32:41,975 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-7) execute command: getDebitData
      2017-09-27 15:32:41,976 DEBUG [com.netflix.hystrix.contrib.javanica.command.GenericCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-4) execute command: getDebitData
      2017-09-27 15:32:41,976 DEBUG [com.netflix.hystrix.AbstractCommand] (hystrix-Adapter$Proxy$_$$_WeldSubclass-4) HystrixCommand execution REJECTED_THREAD_EXECUTION and fallback failed.: java.lan
      g.RuntimeException: No fallback available.
      [...]
      Caused by: java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@6ad88423 rejected from java.util.concurrent.ThreadPoolExecutor@797ba7e8[Running, pool size = 10, active threads = 10, queued tasks = 0, completed tasks = 180]

       

      Hystrix tries many times to execute the command instead of once. The thread pool doesn't have enough size. The connection to the server will never be executed. If I remove the HystricCommand the code works as expected.

      The only parameter which is set is: hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds 60000

       

      Does anybody know what happens in the background? Why ist the command executed more than once? How can I get the correct behaviour?

       

      Thanks in advance,

      Markus

        • 1. Re: HystrixCommand and Weld
          turbotrakt0r

          Hi Markus,

           

          regarding to your problem.

           

          You can add a stateless annotation to your adapter-classes containing the HystrixCommand-Annotations.

           

          Wildfly 10 uses weld dependency injection for every non-ejb classes. By adding stateless annotations you're converting your class to a java-ee bean. The application server will then inject your beans according to the java-ee standard.

           

          Best regards,

          Tobias