com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook Java Examples

The following examples show how to use com.netflix.hystrix.strategy.executionhook.HystrixCommandExecutionHook. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ThreadLocalConfiguration.java    From spring-microservices-in-action with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
	// Keeps references of existing Hystrix plugins.
	HystrixEventNotifier        eventNotifier        = HystrixPlugins.getInstance().getEventNotifier();
       HystrixMetricsPublisher     metricsPublisher     = HystrixPlugins.getInstance().getMetricsPublisher();
       HystrixPropertiesStrategy   propertiesStrategy   = HystrixPlugins.getInstance().getPropertiesStrategy();
       HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

       HystrixPlugins.reset();

       HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy));  // Register your customized strategy ({@code ThreadLocalAwareStrategy})
       HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
       HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
       HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
       HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #2
Source File: AbstractContextConcurrencyStrategy.java    From onetwo with Apache License 2.0 6 votes vote down vote up
public AbstractContextConcurrencyStrategy(HystrixConcurrencyStrategy existingConcurrencyStrategy) {
	if (getClass().isInstance(existingConcurrencyStrategy)) {
		System.out.println("Welcome to singleton hell...");
		return;
	}
	
	this.existingConcurrencyStrategy = existingConcurrencyStrategy;
	
	HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
			.getEventNotifier();
	HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
			.getMetricsPublisher();
	HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
			.getPropertiesStrategy();
	HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
			.getCommandExecutionHook();

	HystrixPlugins.reset();

	// Registers existing plugins excepts the Concurrent Strategy plugin.
	HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
	HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
	HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
	HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
	HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #3
Source File: MultiConfigs.java    From astrix with Apache License 2.0 6 votes vote down vote up
private static void registerWithHystrix() {

        final HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
        final HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
        final HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
        final HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
        final HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

        HystrixPlugins.reset();

        reRegister(eventNotifier, multiEventNotifierDispatcher, notifier -> HystrixPlugins.getInstance().registerEventNotifier(notifier));
        reRegister(concurrencyStrategy, multiConcurrencyStrategyDispatcher, strategy -> HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy));
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        reRegister(propertiesStrategy, multiPropertiesStrategyDispatcher, strategy -> HystrixPlugins.getInstance().registerPropertiesStrategy(strategy));
        HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);

        LOGGER.info(MultiPropertiesStrategyDispatcher.class.getName() + " registered with Hystrix!");
    }
 
Example #4
Source File: HystrixPluginsInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    SWHystrixPluginsWrapperCache wrapperCache = (SWHystrixPluginsWrapperCache) objInst.getSkyWalkingDynamicField();
    if (wrapperCache == null || wrapperCache.getSwExecutionHookWrapper() == null) {
        synchronized (objInst) {
            if (wrapperCache == null) {
                wrapperCache = new SWHystrixPluginsWrapperCache();
                objInst.setSkyWalkingDynamicField(wrapperCache);
            }
            if (wrapperCache.getSwExecutionHookWrapper() == null) {
                // Return and register wrapper only for the first time
                // Try to believe that all other hooks will use the their delegates
                SWExecutionHookWrapper wrapper = new SWExecutionHookWrapper((HystrixCommandExecutionHook) ret);
                wrapperCache.setSwExecutionHookWrapper(wrapper);

                registerSWExecutionHookWrapper(wrapper);

                return wrapper;
            }
        }
    }

    return ret;
}
 
Example #5
Source File: RouterHystrixConcurrencyStrategy.java    From spring-cloud-huawei with Apache License 2.0 6 votes vote down vote up
public RouterHystrixConcurrencyStrategy() {
  HystrixConcurrencyStrategy strategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
  if (strategy instanceof RouterHystrixConcurrencyStrategy) {
    return;
  }
  HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
      .getCommandExecutionHook();
  HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
  HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
  HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
      .getPropertiesStrategy();
  HystrixPlugins.reset();
  HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
  HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
  HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
  HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
  HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
}
 
Example #6
Source File: HystrixMetricsBinder.java    From micrometer with Apache License 2.0 6 votes vote down vote up
@Override
public void bindTo(MeterRegistry registry) {
    // Keeps references of existing Hystrix plugins.
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();

    HystrixPlugins.reset();

    // Registers existing plugins except the new MicroMeter Strategy plugin.
    HystrixPlugins.getInstance().registerMetricsPublisher(new MicrometerMetricsPublisher(registry, metricsPublisher));
    HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy);
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #7
Source File: SeataHystrixConcurrencyStrategy.java    From spring-cloud-alibaba with Apache License 2.0 6 votes vote down vote up
public SeataHystrixConcurrencyStrategy() {
	try {
		this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
		if (this.delegate instanceof SeataHystrixConcurrencyStrategy) {
			return;
		}
		HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
		HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
		HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
		HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
		logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy);
		HystrixPlugins.reset();
		HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
		HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
		HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
		HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
		HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
	} catch (Exception ex) {
		logger.error("Failed to register Seata Hystrix Concurrency Strategy", ex);
	}
}
 
Example #8
Source File: PreservesExecutionContextHystrixStrategy.java    From spring-cloud-ribbon-extensions with Apache License 2.0 6 votes vote down vote up
/**
 * registers the {@link ExecutionContextAwareHystrixStrategy}
 */
public static void init() {
    // keeps references of existing Hystrix plugins.
    HystrixConcurrencyStrategy existingConcurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    // reset the Hystrix plugin
    HystrixPlugins.reset();
    // configure the  plugin
    HystrixPlugins.getInstance().registerConcurrencyStrategy(new ExecutionContextAwareHystrixStrategy(existingConcurrencyStrategy));
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
    log.info("Context propagation enabled for Hystrix.");
}
 
Example #9
Source File: BladeHystrixAutoConfiguration.java    From blade-tool with GNU Lesser General Public License v3.0 6 votes vote down vote up
@PostConstruct
public void init() {
	// Keeps references of existing Hystrix plugins.
	HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
	HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
	HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
	HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

	HystrixPlugins.reset();

	// Registers existing plugins excepts the Concurrent Strategy plugin.
	HystrixConcurrencyStrategy strategy = new BladeHystrixConcurrencyStrategy(existingConcurrencyStrategy, accountGetter, properties);
	HystrixPlugins.getInstance().registerConcurrencyStrategy(strategy);
	HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
	HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
	HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
	HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #10
Source File: ThreadLocalConfiguration.java    From spring-microservices-in-action with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
	// Keeps references of existing Hystrix plugins.
	HystrixEventNotifier        eventNotifier        = HystrixPlugins.getInstance().getEventNotifier();
       HystrixMetricsPublisher     metricsPublisher     = HystrixPlugins.getInstance().getMetricsPublisher();
       HystrixPropertiesStrategy   propertiesStrategy   = HystrixPlugins.getInstance().getPropertiesStrategy();
       HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

       HystrixPlugins.reset();

       HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy));  // Register your customized strategy ({@code ThreadLocalAwareStrategy})
       HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
       HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
       HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
       HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #11
Source File: ThreadLocalConfiguration.java    From spring-microservices-in-action with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
	// Keeps references of existing Hystrix plugins.
	HystrixEventNotifier        eventNotifier        = HystrixPlugins.getInstance().getEventNotifier();
       HystrixMetricsPublisher     metricsPublisher     = HystrixPlugins.getInstance().getMetricsPublisher();
       HystrixPropertiesStrategy   propertiesStrategy   = HystrixPlugins.getInstance().getPropertiesStrategy();
       HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

       HystrixPlugins.reset();

       HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy));  // Register your customized strategy ({@code ThreadLocalAwareStrategy})
       HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
       HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
       HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
       HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #12
Source File: ThreadLocalConfiguration.java    From spring-microservices-in-action with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {
	// Keeps references of existing Hystrix plugins.
	HystrixEventNotifier        eventNotifier        = HystrixPlugins.getInstance().getEventNotifier();
       HystrixMetricsPublisher     metricsPublisher     = HystrixPlugins.getInstance().getMetricsPublisher();
       HystrixPropertiesStrategy   propertiesStrategy   = HystrixPlugins.getInstance().getPropertiesStrategy();
       HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

       HystrixPlugins.reset();

       HystrixPlugins.getInstance().registerConcurrencyStrategy(new ThreadLocalAwareStrategy(existingConcurrencyStrategy));  // Register your customized strategy ({@code ThreadLocalAwareStrategy})
       HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
       HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
       HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
       HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #13
Source File: GrayHystrixContextConcurrencyStrategy.java    From spring-cloud-gray with Apache License 2.0 6 votes vote down vote up
public GrayHystrixContextConcurrencyStrategy() {
    this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
    if (this.delegate instanceof GrayHystrixContextConcurrencyStrategy) {
        return;
    }
    // Keeps references of existing Hystrix plugins.
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();

    HystrixPlugins.reset();

    // Registers existing plugins excepts the Concurrent Strategy plugin.
    HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
}
 
Example #14
Source File: HystrixPluginsInterceptorTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testInterceptorWithCustomHystrixCommandExecutionHook() throws Throwable {
    Object wrapperResult = getCommandExecutionHookByInterceptor();
    assertTrue(wrapperResult instanceof SWExecutionHookWrapper);
    assertSame(HystrixPlugins.getInstance().getCommandExecutionHook(), wrapperResult);

    // register custom HystrixCommandExecutionHook
    HystrixCommandExecutionHook delegate = getCommandExecutionHookByInterceptor();
    HystrixCommandExecutionHook customCommandExecutionHook = new CustomHystrixCommandExecutionHook(delegate);
    HystrixPlugins.reset();
    HystrixPlugins.getInstance().registerCommandExecutionHook(customCommandExecutionHook);

    // custom HystrixCommandExecutionHook can be consumed
    wrapperResult = getCommandExecutionHookByInterceptor();
    assertSame(customCommandExecutionHook, wrapperResult);
    assertSame(HystrixPlugins.getInstance().getCommandExecutionHook(), wrapperResult);
}
 
Example #15
Source File: SofaTracerHystrixConcurrencyStrategy.java    From sofa-tracer with Apache License 2.0 6 votes vote down vote up
public SofaTracerHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof SofaTracerHystrixConcurrencyStrategy) {
            // Welcome to singleton hell...
            return;
        }
        HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance()
            .getCommandExecutionHook();
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
            .getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
            .getPropertiesStrategy();
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
        HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception ex) {
        SelfLog.error("Failed to register Sleuth Hystrix Concurrency Strategy", ex);
    }
}
 
Example #16
Source File: ThreadLocalProcessHystrixConcurrencyStrategy.java    From Aooms with Apache License 2.0 6 votes vote down vote up
public ThreadLocalProcessHystrixConcurrencyStrategy() {
	try {

		this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
		if (this.delegate instanceof ThreadLocalProcessHystrixConcurrencyStrategy) {
			// Welcome to singleton hell...
			return;
		}
		HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
		HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
		HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
		HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();

		this.logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy);

		HystrixPlugins.reset();
		HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
		HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
		HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
		HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
		HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
	}
	catch (Exception e) {
		log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e);
	}
}
 
Example #17
Source File: RequestAttributeHystrixAutoConfiguration.java    From summerframework with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void init() {

    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();

    HystrixPlugins.reset();

    HystrixPlugins.getInstance()
        .registerConcurrencyStrategy(new RequestAttributeHystrixConcurrencyStrategy(existingConcurrencyStrategy));
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
}
 
Example #18
Source File: MetricsPublisherRegistrationTest.java    From prometheus-hystrix with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReRegisterCustomHystrixPlugins() {
    // given
    // ... a plugin is already registered
    HystrixCommandExecutionHook plugin = new HystrixCommandExecutionHook() {
    };
    HystrixPlugins.getInstance().registerCommandExecutionHook(plugin);

    // when
    // ... we register
    HystrixPrometheusMetricsPublisher.builder().shouldRegisterDefaultPlugins(false).buildAndRegister();

    // then
    // ... the other plugin is still registered.
    assertThat(HystrixPlugins.getInstance().getCommandExecutionHook()).isEqualTo(plugin);
}
 
Example #19
Source File: RegisterCommandExcutionHook.java    From jframework with Apache License 2.0 6 votes vote down vote up
public RegisterCommandExcutionHook() {
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixConcurrencyStrategy concurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
    HystrixMetricsPublisher hystrixMetricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();

    HystrixPlugins.reset();
    HystrixPlugins.getInstance().registerMetricsPublisher(hystrixMetricsPublisher);
    HystrixPlugins.getInstance().registerConcurrencyStrategy(concurrencyStrategy);
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    HystrixPlugins.getInstance().registerCommandExecutionHook(new HystrixCommandExecutionHook() {
        @Override
        public <T> void onFallbackStart(HystrixInvokable<T> commandInstance) {
            HystrixCommand hystrixCommand = (HystrixCommand) commandInstance;
            String commandKey = hystrixCommand.getCommandKey().toString();
            log.error("Hystrix: {} 接口开始降级", commandKey);
            super.onFallbackStart(commandInstance);
        }
    });
}
 
Example #20
Source File: CustomFeignHystrixConcurrencyStrategy.java    From spring-microservice-exam with MIT License 6 votes vote down vote up
public CustomFeignHystrixConcurrencyStrategy() {
    try {
        this.hystrixConcurrencyStrategy = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.hystrixConcurrencyStrategy instanceof CustomFeignHystrixConcurrencyStrategy) {
            // Welcome to singleton hell...
            return;
        }
        HystrixCommandExecutionHook commandExecutionHook =
                HystrixPlugins.getInstance().getCommandExecutionHook();
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy =
                HystrixPlugins.getInstance().getPropertiesStrategy();
        this.logCurrentStateOfHystrixPlugins(eventNotifier, metricsPublisher, propertiesStrategy);
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
        HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        log.error("Failed to register Sleuth Hystrix Concurrency Strategy", e);
    }
}
 
Example #21
Source File: TenacityConfiguredBundleBuilderTest.java    From tenacity with Apache License 2.0 6 votes vote down vote up
@Test
public void withExecutionMappers() throws Exception {
    final HystrixCommandExecutionHook hook = new ExceptionLoggingCommandHook();
    final TenacityConfiguredBundle<Configuration> bundle = TenacityBundleBuilder
            .newBuilder()
            .configurationFactory(CONFIGURATION_FACTORY)
            .commandExecutionHook(hook)
            .build();

    assertThat(bundle)
            .isEqualTo(new TenacityConfiguredBundle<>(
                    CONFIGURATION_FACTORY,
                    Optional.of(hook),
                    Collections.<ExceptionMapper<? extends Throwable>>emptyList()
            ));
}
 
Example #22
Source File: HmilyHystrixConcurrencyStrategy.java    From hmily with Apache License 2.0 5 votes vote down vote up
public HmilyHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof HmilyHystrixConcurrencyStrategy) {
            return;
        }
        HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins
                .getInstance().getCommandExecutionHook();
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
                .getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
                .getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
                .getPropertiesStrategy();
        LOGGER.debug("HystrixEventNotifier:{}, HystrixMetricsPublisher:{}, HystrixPropertiesStrategy:{}",
                eventNotifier, metricsPublisher, propertiesStrategy);
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
        HystrixPlugins.getInstance()
                .registerCommandExecutionHook(commandExecutionHook);
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        LOGGER.error("Failed to register Tracing Hystrix Concurrency Strategy", e);
    }
}
 
Example #23
Source File: HystrixConcurrencyStrategyInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void registerSWHystrixConcurrencyStrategyWrapper(SWHystrixConcurrencyStrategyWrapper wrapper) {
    // Copy from Spring Cloud Sleuth
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixPlugins.reset();
    HystrixPlugins.getInstance().registerConcurrencyStrategy(wrapper);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
}
 
Example #24
Source File: DelayedTenacityConfiguredBundle.java    From breakerbox with Apache License 2.0 5 votes vote down vote up
public DelayedTenacityConfiguredBundle(TenacityBundleConfigurationFactory<BreakerboxServiceConfiguration> tenacityBundleConfigurationFactory,
                                       Optional<HystrixCommandExecutionHook> hystrixCommandExecutionHook,
                                       Iterable<ExceptionMapper<? extends Throwable>> exceptionMappers,
                                       boolean usingTenacityCircuitBreakerHealthCheck,
                                       boolean usingAdminPort) {
    super(tenacityBundleConfigurationFactory, hystrixCommandExecutionHook, exceptionMappers, usingTenacityCircuitBreakerHealthCheck, usingAdminPort);
}
 
Example #25
Source File: TenacityConfiguredBundle.java    From tenacity with Apache License 2.0 5 votes vote down vote up
public TenacityConfiguredBundle(
        TenacityBundleConfigurationFactory<T> tenacityBundleConfigurationFactory,
        Optional<HystrixCommandExecutionHook> hystrixCommandExecutionHook,
        Iterable<ExceptionMapper<? extends Throwable>> exceptionMappers,
        boolean usingTenacityCircuitBreakerHealthCheck,
        boolean usingAdminPort) {
    this.exceptionMappers = exceptionMappers;
    this.tenacityBundleConfigurationFactory = checkNotNull(tenacityBundleConfigurationFactory);
    this.executionHook = hystrixCommandExecutionHook;
    this.usingTenacityCircuitBreakerHealthCheck = usingTenacityCircuitBreakerHealthCheck;
    this.usingAdminPort = usingAdminPort;
}
 
Example #26
Source File: AbstractTenacityPropertyKeys.java    From tenacity with Apache License 2.0 5 votes vote down vote up
public AbstractTenacityPropertyKeys(TenacityPropertyKeyFactory keyFactory,
                                    Iterable<TenacityPropertyKey> keys,
                                    Iterable<ExceptionMapper<? extends Throwable>> exceptionMappers,
                                    Optional<HystrixCommandExecutionHook> executionHook) {
    this.keys = ImmutableList.copyOf(checkNotNull(keys));
    this.keyFactory = checkNotNull(keyFactory);
    this.exceptionMappers = ImmutableList.copyOf(checkNotNull(exceptionMappers));
    this.executionHook = executionHook;
}
 
Example #27
Source File: SpringCloudDtsContextHystrixConcurrencyStrategy.java    From dts with Apache License 2.0 5 votes vote down vote up
public SpringCloudDtsContextHystrixConcurrencyStrategy() {
    HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins.getInstance().getCommandExecutionHook();
    HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance().getEventNotifier();
    HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance().getMetricsPublisher();
    HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance().getPropertiesStrategy();
    HystrixPlugins.reset();
    HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
    HystrixPlugins.getInstance().registerCommandExecutionHook(commandExecutionHook);
    HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
    HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
    HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
}
 
Example #28
Source File: MythHystrixConcurrencyStrategy.java    From myth with Apache License 2.0 5 votes vote down vote up
public MythHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof MythHystrixConcurrencyStrategy) {
            return;
        }
        HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins
                .getInstance().getCommandExecutionHook();
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
                .getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
                .getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
                .getPropertiesStrategy();
        LOGGER.debug("HystrixEventNotifier:{}, HystrixMetricsPublisher:{}, HystrixPropertiesStrategy:{}",
                eventNotifier, metricsPublisher, propertiesStrategy);
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
        HystrixPlugins.getInstance()
                .registerCommandExecutionHook(commandExecutionHook);
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        LOGGER.error("Failed to register Tracing Hystrix Concurrency Strategy", e);
    }
}
 
Example #29
Source File: TracingHystrixConcurrencyStrategy.java    From tx-lcn with Apache License 2.0 5 votes vote down vote up
public TracingHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof TracingHystrixConcurrencyStrategy) {
            log.debug("Non another HystrixConcurrencyStrategy.");
            return;
        }
        HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins
                .getInstance().getCommandExecutionHook();
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
                .getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
                .getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
                .getPropertiesStrategy();
        log.debug("HystrixEventNotifier:{}, HystrixMetricsPublisher:{}, HystrixPropertiesStrategy:{}",
                eventNotifier, metricsPublisher, propertiesStrategy);
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
        HystrixPlugins.getInstance()
                .registerCommandExecutionHook(commandExecutionHook);
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        log.error("Failed to register Tracing Hystrix Concurrency Strategy", e);
    }
}
 
Example #30
Source File: RaincatHystrixConcurrencyStrategy.java    From Raincat with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new Raincat hystrix concurrency strategy.
 */
public RaincatHystrixConcurrencyStrategy() {
    try {
        this.delegate = HystrixPlugins.getInstance().getConcurrencyStrategy();
        if (this.delegate instanceof RaincatHystrixConcurrencyStrategy) {
            return;
        }
        HystrixCommandExecutionHook commandExecutionHook = HystrixPlugins
                .getInstance().getCommandExecutionHook();
        HystrixEventNotifier eventNotifier = HystrixPlugins.getInstance()
                .getEventNotifier();
        HystrixMetricsPublisher metricsPublisher = HystrixPlugins.getInstance()
                .getMetricsPublisher();
        HystrixPropertiesStrategy propertiesStrategy = HystrixPlugins.getInstance()
                .getPropertiesStrategy();
        LOGGER.debug("HystrixEventNotifier:{}, HystrixMetricsPublisher:{}, HystrixPropertiesStrategy:{}",
                eventNotifier, metricsPublisher, propertiesStrategy);
        HystrixPlugins.reset();
        HystrixPlugins.getInstance().registerConcurrencyStrategy(this);
        HystrixPlugins.getInstance()
                .registerCommandExecutionHook(commandExecutionHook);
        HystrixPlugins.getInstance().registerEventNotifier(eventNotifier);
        HystrixPlugins.getInstance().registerMetricsPublisher(metricsPublisher);
        HystrixPlugins.getInstance().registerPropertiesStrategy(propertiesStrategy);
    } catch (Exception e) {
        LOGGER.error("Failed to register Tracing Hystrix Concurrency Strategy", e);
    }
}