Unable to get custom HystrixCommandExecutionHook to work

560 views
Skip to first unread message

Joe Public

unread,
Aug 27, 2013, 10:41:38 AM8/27/13
to hystr...@googlegroups.com
Hello,

I subclassed the HystrixCommandExecutionHook and created a class called MyHystrixCommandExecutionHook.  I then tried to register in a static initialization block within my web application like this:

HystrixPlugins.getInstance().registerCommandExecutionHook(new MyHystrixCommandExecutionHook());

For now, this class does nothing but override each of the method, write to system.out and then call the default method implementation in the super class.

While it seems straight forward, it doesn't appear that my custom HystrixCommandExecutionHook is getting called.  Is there something that I missed?

Thanks,

Joe

Ben Christensen

unread,
Aug 27, 2013, 5:08:56 PM8/27/13
to Joe Public, hystr...@googlegroups.com
That code looks correct.

Can you confirm you are not getting an IllegalStateException when registering?


This is just to confirm that you are indeed initializing it before anything uses Hystrix.


You could also call HystrixPlugins.getCommandExecutionHook() and confirm it has your implementation registered.

Other than that, the hooks get invoked and there is nothing else special about it. I just did some testing with the code and it seems to be working okay, so perhaps some more log statements or connecting a debugger could suggest what's going on?

Here is my test code:

import com.netflix.hystrix.HystrixCommand;

import com.netflix.hystrix.HystrixCommandGroupKey;

import com.netflix.hystrix.strategy.HystrixPlugins;

import com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook;


public class Test {


    /**

     * @param args

     */

    public static void main(String[] args) {

        HystrixPlugins.getInstance().registerCommandExecutionHook(new HystrixCommandExecutionHook() {

            @Override

            public <T> void onRunStart(HystrixCommand<T> commandInstance) {

                super.onRunStart(commandInstance);


                System.out.println("*** Starting ***");

            }

        });


        System.out.println("Execution => " + new HystrixCommand<String>(HystrixCommandGroupKey.Factory.asKey("Testing")) {


            @Override

            protected String run() throws Exception {

                return "Hello World";

            }


        }.execute());

    }


}


It outputs this:


*** Starting ***

Execution => Hello World




-- 
Ben Christensen - Edge Service Platform Team
+1.310.782.5511 @benjchristensen
--
You received this message because you are subscribed to the Google Groups "HystrixOSS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hystrixoss+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages