com.netflix.hystrix.HystrixObservableCommand Java Examples

The following examples show how to use com.netflix.hystrix.HystrixObservableCommand. 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: HystrixCommandConstructorInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    String commandIdentify = "";

    if (HystrixCommand.class.isAssignableFrom(objInst.getClass())) {
        HystrixCommand hystrixCommand = (HystrixCommand) objInst;
        commandIdentify = hystrixCommand.getCommandKey().name();
    } else if (HystrixCollapser.class.isAssignableFrom(objInst.getClass())) {
        HystrixCollapser hystrixCollapser = (HystrixCollapser) objInst;
        commandIdentify = hystrixCollapser.getCollapserKey().name();
    } else if (HystrixObservableCollapser.class.isAssignableFrom(objInst.getClass())) {
        HystrixObservableCollapser hystrixObservableCollapser = (HystrixObservableCollapser) objInst;
        commandIdentify = hystrixObservableCollapser.getCollapserKey().name();
    } else if (HystrixObservableCommand.class.isAssignableFrom(objInst.getClass())) {
        HystrixObservableCommand hystrixObservableCommand = (HystrixObservableCommand) objInst;
        commandIdentify = hystrixObservableCommand.getCommandKey().name();
    }

    objInst.setSkyWalkingDynamicField(new EnhanceRequireObjectCache(OPERATION_NAME_PREFIX + commandIdentify));
}
 
Example #2
Source File: HttpResourceObservableCommand.java    From ribbon with Apache License 2.0 6 votes vote down vote up
public HttpResourceObservableCommand(HttpClient<ByteBuf, ByteBuf> httpClient,
                                     HttpClientRequest<ByteBuf> httpRequest, String hystrixCacheKey,
                                     Map<String, Object> requestProperties,
                                     FallbackHandler<T> fallbackHandler,
                                     ResponseValidator<HttpClientResponse<ByteBuf>> validator,
                                     Class<? extends T> classType,
                                     HystrixObservableCommand.Setter setter) {
    super(setter);
    this.httpClient = httpClient;
    this.fallbackHandler = fallbackHandler;
    this.validator = validator;
    this.httpRequest = httpRequest;
    this.hystrixCacheKey = hystrixCacheKey;
    this.classType = classType;
    this.requestProperties = requestProperties;
}
 
Example #3
Source File: ReactiveHystrixCircuitBreaker.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 6 votes vote down vote up
private <T> HystrixObservableCommand<T> createCommand(Publisher<T> toRun, Function fallback) {
	HystrixObservableCommand.Setter setter = HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
			.andCommandPropertiesDefaults(commandPropertiesSetter);
	HystrixObservableCommand<T> command = new HystrixObservableCommand<T>(setter) {
		@Override
		protected Observable<T> construct() {
			return RxReactiveStreams.toObservable(toRun);
		}

		@Override
		protected Observable<T> resumeWithFallback() {
			if(fallback == null) {
				super.resumeWithFallback();
			}
			return RxReactiveStreams.toObservable((Publisher)fallback.apply(this.getExecutionException()));
		}
	};
	return command;
}
 
Example #4
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCacheKeyWithContextInitializedConsumer() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  HystrixRequestContext.initializeContext();
  String cacheKey = bizkeeperCommand.getCacheKey();
  Assert.assertNotNull(cacheKey);
}
 
Example #5
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructConsumer() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  Observable<Response> response = bizkeeperCommand.construct();
  Assert.assertNotNull(response);
}
 
Example #6
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testResumeWithFallbackConsumer() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ConsumerBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
  Assert.assertNotNull(observe);
}
 
Example #7
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetCacheKeyWithContextInitializedProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  HystrixRequestContext.initializeContext();
  String cacheKey = bizkeeperCommand.getCacheKey();
  Assert.assertNotNull(cacheKey);
}
 
Example #8
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConstructProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  Observable<Response> response = bizkeeperCommand.construct();
  Assert.assertNotNull(response);
}
 
Example #9
Source File: TestBizkeeperCommand.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Test
public void testResumeWithFallbackProvider() {

  Invocation invocation = Mockito.mock(Invocation.class);
  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(true)
      .withRequestLogEnabled(false);

  BizkeeperCommand bizkeeperCommand = new ProviderBizkeeperCommand("groupname", invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey("groupname", invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey("groupname", invocation))
          .andCommandPropertiesDefaults(setter));

  Observable<Response> observe = bizkeeperCommand.resumeWithFallback();
  Assert.assertNotNull(observe);
}
 
Example #10
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void toObservable() throws Exception {
    final String name = "Pinpoint";
    final String expectedMessage = HystrixTestHelper.sayHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.create(commandGroup, name);
    String actualMessage = helloObservableCommand.toObservable()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example #11
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void observe() throws Exception {
    final String name = "Pinpoint";
    final String expectedMessage = HystrixTestHelper.sayHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.create(commandGroup, name);
    String actualMessage = helloObservableCommand.observe()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example #12
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void observeWithException(Exception expectedException) throws Exception {
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.createForException(commandGroup, name, expectedException);
    String actualMessage = helloObservableCommand.observe()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example #13
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void observeWithTimeout() throws Exception {
    // reducing this too much will make the actual task to not be scheduled at all
    final int timeoutMs = 100;
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.createForTimeout(commandGroup, name, timeoutMs);
    String actualMessage = helloObservableCommand.observe()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush(timeoutMs);
}
 
Example #14
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void observeWithShortCircuit() throws Exception {
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.createForShortCircuit(commandGroup, name);
    String actualMessage = helloObservableCommand.observe()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example #15
Source File: ReactiveHystrixCircuitBreaker.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 5 votes vote down vote up
public <T> Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> fallback) {
	HystrixObservableCommand<T> command = createCommand(toRun, fallback);

	return Mono.create(s -> {
		Subscription sub = command.toObservable().subscribe(s::success, s::error, s::success);
		s.onCancel(sub::unsubscribe);
	});
}
 
Example #16
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void toObservableWithException(Exception expectedException) throws Exception {
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.createForException(commandGroup, name, expectedException);
    String actualMessage = helloObservableCommand.toObservable()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example #17
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void toObservableWithTimeout() throws Exception {
    // reducing this too much will make the actual task to not be scheduled at all
    final int timeoutMs = 100;
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.createForTimeout(commandGroup, name, timeoutMs);
    String actualMessage = helloObservableCommand.toObservable()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush(timeoutMs);
}
 
Example #18
Source File: HystrixObservableCommandTestRunner.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public void toObservableWithShortCircuit() throws Exception {
    final String name = "Pinpoint";
    final String expectedFallbackMessage = HystrixTestHelper.fallbackHello(name);
    HystrixObservableCommand<String> helloObservableCommand = SayHelloObservableCommand.createForShortCircuit(commandGroup, name);
    String actualMessage = helloObservableCommand.toObservable()
            .toBlocking()
            .single();
    Assert.assertEquals(expectedFallbackMessage, actualMessage);

    HystrixTestHelper.waitForSpanDataFlush();
}
 
Example #19
Source File: BookmarkCommand.java    From ReactiveLab with Apache License 2.0 5 votes vote down vote up
@Override
protected HystrixObservableCommand<Bookmark> createCommand(Collection<CollapsedRequest<Bookmark, Video>> requests) {
    List<Video> videos = new ArrayList<>();
    for (CollapsedRequest<Bookmark, Video> r : requests) {
        videos.add(r.getArgument());
    }
    return new BookmarksCommand(videos, loadBalancer);
}
 
Example #20
Source File: HystrixObservableCommandChain.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public Observable<ResultCommandPair<T>> toResultCommandPairObservable() {
    Observable<ResultCommandPair<T>> rootObservable = null;
    for (final HystrixObservableCommand<T> command : hystrixCommands) {
        Observable<ResultCommandPair<T>> observable = command.toObservable().map(new Func1<T, ResultCommandPair<T>>() {
            @Override
            public ResultCommandPair<T> call(T result) {
                return new ResultCommandPair<T>(result, command);
            }
        });
        rootObservable = rootObservable == null ? observable : rootObservable.onErrorResumeNext(observable);
    }
    return rootObservable;
}
 
Example #21
Source File: HystrixObservableCommandChain.java    From ribbon with Apache License 2.0 5 votes vote down vote up
public Observable<T> toObservable() {
    Observable<T> rootObservable = null;
    for (final HystrixObservableCommand<T> command : hystrixCommands) {
        Observable<T> observable = command.toObservable();
        rootObservable = rootObservable == null ? observable : rootObservable.onErrorResumeNext(observable);
    }
    return rootObservable;
}
 
Example #22
Source File: HttpRequest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
HystrixObservableCommandChain<T> createHystrixCommandChain() {
    List<HystrixObservableCommand<T>> commands = new ArrayList<HystrixObservableCommand<T>>(2);
    if (cacheProvider != null) {
        commands.add(new CacheObservableCommand<T>(cacheProvider.getCacheProvider(), cacheProvider.getKey(), cacheHystrixCacheKey,
                requestProperties, template.cacheHystrixProperties()));
    }
    commands.add(new HttpResourceObservableCommand<T>(client, httpRequest, hystrixCacheKey, requestProperties, template.fallbackHandler(),
            template.responseValidator(), template.getClassType(), template.hystrixProperties()));

    return new HystrixObservableCommandChain<T>(commands);
}
 
Example #23
Source File: HttpMetaRequest.java    From ribbon with Apache License 2.0 5 votes vote down vote up
private Observable<RibbonResponse<Observable<T>>> convertToRibbonResponse(
        final HystrixObservableCommandChain<T> commandChain, final Observable<ResultCommandPair<T>> hystrixNotificationObservable) {
    return Observable.create(new OnSubscribe<RibbonResponse<Observable<T>>>() {
        @Override
        public void call(
                final Subscriber<? super RibbonResponse<Observable<T>>> t1) {
            final Subject<T, T> subject = ReplaySubject.create();
            hystrixNotificationObservable.materialize().subscribe(new Action1<Notification<ResultCommandPair<T>>>() {
                AtomicBoolean first = new AtomicBoolean(true);

                @Override
                public void call(Notification<ResultCommandPair<T>> notification) {
                    if (first.compareAndSet(true, false)) {
                        HystrixObservableCommand<T> command = notification.isOnError() ? commandChain.getLastCommand() : notification.getValue().getCommand();
                        t1.onNext(new ResponseWithSubject<T>(subject, command));
                        t1.onCompleted();
                    }
                    if (notification.isOnNext()) {
                        subject.onNext(notification.getValue().getResult());
                    } else if (notification.isOnCompleted()) {
                        subject.onCompleted();
                    } else { // onError
                        subject.onError(notification.getThrowable());
                    }
                }
            });
        }
    });
}
 
Example #24
Source File: HystrixBuilder.java    From bird-java with MIT License 5 votes vote down vote up
/**
 * this is build HystrixObservableCommand.Setter.
 *
 * @param hystrixHandle {@linkplain HystrixHandle}
 * @return {@linkplain HystrixObservableCommand.Setter}
 */
public static HystrixObservableCommand.Setter build(final HystrixHandle hystrixHandle) {

    if (hystrixHandle.getMaxConcurrentRequests() == 0) {
        hystrixHandle.setMaxConcurrentRequests(GatewayConstant.MAX_CONCURRENT_REQUESTS);
    }
    if (hystrixHandle.getErrorThresholdPercentage() == 0) {
        hystrixHandle.setErrorThresholdPercentage(GatewayConstant.ERROR_THRESHOLD_PERCENTAGE);
    }
    if (hystrixHandle.getRequestVolumeThreshold() == 0) {
        hystrixHandle.setRequestVolumeThreshold(GatewayConstant.REQUEST_VOLUME_THRESHOLD);
    }
    if (hystrixHandle.getSleepWindowInMilliseconds() == 0) {
        hystrixHandle.setSleepWindowInMilliseconds(GatewayConstant.SLEEP_WINDOW_INMILLISECONDS);
    }

    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey(hystrixHandle.getGroupKey());

    HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(hystrixHandle.getCommandKey());

    final HystrixCommandProperties.Setter propertiesSetter =
            HystrixCommandProperties.Setter()
                    .withExecutionTimeoutInMilliseconds(hystrixHandle.getTimeout())
                    .withCircuitBreakerEnabled(true)
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
                    .withExecutionIsolationSemaphoreMaxConcurrentRequests(hystrixHandle.getMaxConcurrentRequests())
                    .withCircuitBreakerErrorThresholdPercentage(hystrixHandle.getErrorThresholdPercentage())
                    .withCircuitBreakerRequestVolumeThreshold(hystrixHandle.getRequestVolumeThreshold())
                    .withCircuitBreakerSleepWindowInMilliseconds(hystrixHandle.getSleepWindowInMilliseconds());

    return HystrixObservableCommand.Setter
            .withGroupKey(groupKey)
            .andCommandKey(commandKey)
            .andCommandPropertiesDefaults(propertiesSetter);
}
 
Example #25
Source File: ReactiveHystrixCircuitbreakerDemoApplication.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 5 votes vote down vote up
@Bean
public Customizer<ReactiveHystrixCircuitBreakerFactory> defaultConfig() {
	return factory -> factory.configureDefault(id -> {
		return HystrixObservableCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(id))
				.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
						.withExecutionTimeoutInMilliseconds(3000));

	});
}
 
Example #26
Source File: ReactiveHystrixCircuitBreaker.java    From spring-cloud-circuitbreaker-demo with Apache License 2.0 5 votes vote down vote up
public <T> Flux<T> run(Flux<T> toRun, Function<Throwable, Flux<T>> fallback) {
	HystrixObservableCommand<T> command = createCommand(toRun, fallback);

	return Flux.create(s -> {
		Subscription sub = command.toObservable().subscribe(s::next, s::error, s::complete);
		s.onCancel(sub::unsubscribe);
	});
}
 
Example #27
Source File: HystrixBuilder.java    From soul with Apache License 2.0 5 votes vote down vote up
/**
 * this is build HystrixObservableCommand.Setter.
 *
 * @param hystrixHandle {@linkplain HystrixHandle}
 * @return {@linkplain HystrixObservableCommand.Setter}
 */
public static HystrixObservableCommand.Setter build(final HystrixHandle hystrixHandle) {
    if (hystrixHandle.getMaxConcurrentRequests() == 0) {
        hystrixHandle.setMaxConcurrentRequests(Constants.MAX_CONCURRENT_REQUESTS);
    }
    if (hystrixHandle.getErrorThresholdPercentage() == 0) {
        hystrixHandle.setErrorThresholdPercentage(Constants.ERROR_THRESHOLD_PERCENTAGE);
    }
    if (hystrixHandle.getRequestVolumeThreshold() == 0) {
        hystrixHandle.setRequestVolumeThreshold(Constants.REQUEST_VOLUME_THRESHOLD);
    }
    if (hystrixHandle.getSleepWindowInMilliseconds() == 0) {
        hystrixHandle.setSleepWindowInMilliseconds(Constants.SLEEP_WINDOW_INMILLISECONDS);
    }
    HystrixCommandGroupKey groupKey = HystrixCommandGroupKey.Factory.asKey(hystrixHandle.getGroupKey());
    HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(hystrixHandle.getCommandKey());
    final HystrixCommandProperties.Setter propertiesSetter =
            HystrixCommandProperties.Setter()
                    .withExecutionTimeoutInMilliseconds((int) hystrixHandle.getTimeout())
                    .withCircuitBreakerEnabled(true)
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
                    .withExecutionIsolationSemaphoreMaxConcurrentRequests(hystrixHandle.getMaxConcurrentRequests())
                    .withCircuitBreakerErrorThresholdPercentage(hystrixHandle.getErrorThresholdPercentage())
                    .withCircuitBreakerRequestVolumeThreshold(hystrixHandle.getRequestVolumeThreshold())
                    .withCircuitBreakerSleepWindowInMilliseconds(hystrixHandle.getSleepWindowInMilliseconds());
    return HystrixObservableCommand.Setter
            .withGroupKey(groupKey)
            .andCommandKey(commandKey)
            .andCommandPropertiesDefaults(propertiesSetter);
}
 
Example #28
Source File: CloudReactiveFeign.java    From feign-reactive with Apache License 2.0 5 votes vote down vote up
@Override
public HystrixObservableCommand.Setter create(Target<?> target, MethodMetadata methodMetadata) {
    String groupKey = target.name();
    String commandKey = methodMetadata.configKey();
    return HystrixObservableCommand.Setter
            .withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
            .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
}
 
Example #29
Source File: LoadBalancingReactiveHttpClientTest.java    From feign-reactive with Apache License 2.0 5 votes vote down vote up
private CloudReactiveFeign.SetterFactory getSetterFactoryWithTimeoutDisabled() {
      return (target, methodMetadata) -> {
	String groupKey = target.name();
	HystrixCommandKey commandKey = HystrixCommandKey.Factory.asKey(methodMetadata.configKey());
	return HystrixObservableCommand.Setter
			.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
			.andCommandKey(commandKey)
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
					.withExecutionTimeoutEnabled(false)
			);
};
  }
 
Example #30
Source File: ProviderBizkeeperHanlder.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
protected BizkeeperCommand createBizkeeperCommand(Invocation invocation) {
  HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
      .withRequestCacheEnabled(false)
      .withRequestLogEnabled(false);
  setCommonProperties(invocation, setter);

  BizkeeperCommand command = new ProviderBizkeeperCommand(groupname, invocation,
      HystrixObservableCommand.Setter
          .withGroupKey(CommandKey.toHystrixCommandGroupKey(groupname, invocation))
          .andCommandKey(CommandKey.toHystrixCommandKey(groupname, invocation))
          .andCommandPropertiesDefaults(setter));
  return command;
}