com.netflix.hystrix.HystrixCommandGroupKey Java Examples

The following examples show how to use com.netflix.hystrix.HystrixCommandGroupKey. 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: PaymentRestHacksControllerV4b.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@FailingOnLastRetry    
public void execute(DelegateExecution ctx) throws Exception {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = (long) ctx.getVariable("amount");

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
      return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  ctx.setVariable("paymentTransactionId", response.transactionId);
}
 
Example #2
Source File: PaymentRestHacksControllerV2.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
public String chargeCreditCard(String customerId, long remainingAmount) {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = remainingAmount;

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
      return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  
  return response.transactionId;
}
 
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: DefaultSetterFactory.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public HystrixCommand.Setter createSetter(FilterInvoker invoker, SofaRequest request) {
    Method clientMethod = request.getMethod();
    if (!SETTER_CACHE.containsKey(clientMethod)) {
        synchronized (DefaultSetterFactory.class) {
            if (!SETTER_CACHE.containsKey(clientMethod)) {
                String interfaceId = invoker.getConfig().getInterfaceId();
                String commandKey = generateCommandKey(interfaceId, request.getMethod());
                HystrixCommand.Setter setter = HystrixCommand.Setter
                    .withGroupKey(HystrixCommandGroupKey.Factory.asKey(interfaceId))
                    .andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
                SETTER_CACHE.put(clientMethod, setter);
            }
        }
    }
    return SETTER_CACHE.get(clientMethod);
}
 
Example #5
Source File: PaymentRestHacksControllerV3b.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@FailingOnLastRetry
public void execute(DelegateExecution ctx) throws Exception {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = (long) ctx.getVariable("amount");

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
        return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  ctx.setVariable("paymentTransactionId", response.transactionId);
}
 
Example #6
Source File: HelloDegrade.java    From TakinRPC with Apache License 2.0 6 votes vote down vote up
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(20).withKeepAliveTimeMinutes(5).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(100);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)//
                    .withFallbackEnabled(true).withFallbackIsolationSemaphoreMaxConcurrentRequests(100)//
                    .withExecutionIsolationThreadInterruptOnFutureCancel(true)//
                    .withExecutionIsolationThreadInterruptOnTimeout(true)//
                    .withExecutionTimeoutEnabled(true).withExecutionTimeoutInMilliseconds(1000);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
Example #7
Source File: GrpcHystrixCommand.java    From saluki with Apache License 2.0 6 votes vote down vote up
public GrpcHystrixCommand(String serviceName, String methodName, Boolean isEnabledFallBack) {
  super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(serviceName))//
      .andCommandKey(HystrixCommandKey.Factory.asKey(serviceName + ":" + methodName))//
      .andCommandPropertiesDefaults(
          HystrixCommandProperties.Setter().withCircuitBreakerRequestVolumeThreshold(20)// 10秒钟内至少19此请求失败,熔断器才发挥起作用
              .withCircuitBreakerSleepWindowInMilliseconds(30000)// 熔断器中断请求30秒后会进入半打开状态,放部分流量过去重试
              .withCircuitBreakerErrorThresholdPercentage(50)// 错误率达到50开启熔断保护
              .withExecutionTimeoutEnabled(false)// 禁用这里的超时
              .withFallbackEnabled(isEnabledFallBack))//
      .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(100)
          .withAllowMaximumSizeToDivergeFromCoreSize(true).withMaximumSize(Integer.MAX_VALUE)));
  this.serviceName = serviceName;
  this.methodName = methodName;
  this.start = System.currentTimeMillis();
  this.rpcContext = new ImmutableTriple<Map<String, String>, Map<String, Object>, Set<Class>>(
      RpcContext.getContext().getAttachments(), RpcContext.getContext().get(),
      RpcContext.getContext().getHoldenGroups());
  RpcContext.removeContext();
}
 
Example #8
Source File: PaymentRestHacksControllerV4.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(JobClient client, ActivatedJob job) throws Exception {
     CreateChargeRequest request = new CreateChargeRequest();
     request.amount = (int) job.getVariablesAsMap().get("amount");

     CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
       protected CreateChargeResponse run() throws Exception {
           return rest.postForObject( //
             stripeChargeUrl, //
             request, //
             CreateChargeResponse.class);
       }
     }.execute();
     
     client.newCompleteCommand(job.getKey()) //
       .variables(Collections.singletonMap("paymentTransactionId", response.transactionId))
       .send().join();
   }
 
Example #9
Source File: PaymentRestHacksControllerV2.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
public String chargeCreditCard(String customerId, long remainingAmount) {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = remainingAmount;

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
      return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  
  return response.transactionId;
}
 
Example #10
Source File: PaymentRestHacksControllerV3.java    From flowing-retail with Apache License 2.0 6 votes vote down vote up
@Override
public void handle(JobClient client, ActivatedJob job) throws Exception {
     CreateChargeRequest request = new CreateChargeRequest();
     request.amount = (int) job.getVariablesAsMap().get("amount");

     CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
       protected CreateChargeResponse run() throws Exception {
           return rest.postForObject( //
             stripeChargeUrl, //
             request, //
             CreateChargeResponse.class);
       }
     }.execute();
     
     client.newCompleteCommand(job.getKey()) //
       .variables(Collections.singletonMap("paymentTransactionId", response.transactionId))
       .send().join();
   }
 
Example #11
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 #12
Source File: BookingCommand.java    From resilient-transport-service with Apache License 2.0 5 votes vote down vote up
public BookingCommand(BookingServiceRequestDTO bookingServiceRequestDTO, RestTemplate restTemplate, boolean secondTry) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("BookingServiceClientGroup"))
        .andCommandKey(HystrixCommandKey.Factory.asKey("BookingServiceClient")));

    this.bookingServiceRequestDTO = bookingServiceRequestDTO;
    this.restTemplate = restTemplate;
    this.secondTry = secondTry;
}
 
Example #13
Source File: HystrixConcurrencyStrategyTests.java    From servicecomb-pack with Apache License 2.0 5 votes vote down vote up
public TestCircuitBreakerCommand(String name, OmegaContext omegaContext) {
  super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ThreadPoolTestGroup"))
      .andCommandKey(HystrixCommandKey.Factory.asKey("testCommandKey"))
      .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(name))
      .andThreadPoolPropertiesDefaults(
          HystrixThreadPoolProperties.Setter()
              .withMaxQueueSize(10)
              .withCoreSize(3)
              .withMaximumSize(3)
      )

  );
  this.omegaContext = omegaContext;
}
 
Example #14
Source File: DubboHystrixCommand.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public DubboHystrixCommand(Invoker<?> invoker,Invocation invocation){
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(invoker.getInterface().getName()))
                .andCommandKey(HystrixCommandKey.Factory.asKey(String.format("%s_%d", invocation.getMethodName(),
          invocation.getArguments() == null ? 0 : invocation.getArguments().length)))
          .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                                        .withCircuitBreakerRequestVolumeThreshold(20)//10秒钟内至少19此请求失败,熔断器才发挥起作用
                                        .withCircuitBreakerSleepWindowInMilliseconds(30000)//熔断器中断请求30秒后会进入半打开状态,放部分流量过去重试
                                        .withCircuitBreakerErrorThresholdPercentage(50)//错误率达到50开启熔断保护
                                        .withExecutionTimeoutEnabled(false))//使用dubbo的超时,禁用这里的超时
          .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(getThreadPoolCoreSize(invoker.getUrl()))));//线程池为30
   
    
    this.invoker=invoker;
    this.invocation=invocation;
}
 
Example #15
Source File: CommandWithFallbackViaNetwork.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
public FallbackViaNetwork(int id) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RemoteServiceX"))
            .andCommandKey(HystrixCommandKey.Factory.asKey("GetValueFallbackCommand"))
            // use a different threadpool for the fallback command
            // so saturating the RemoteServiceX pool won't prevent
            // fallbacks from executing
            .andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey("RemoteServiceXFallback")));
    this.id = id;
}
 
Example #16
Source File: MetadataCommand.java    From syndesis with Apache License 2.0 5 votes vote down vote up
MetadataCommand(final MetadataConfigurationProperties configuration, Class<R> type, final Map<String, String> parameters ) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("Meta"))//
        .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter()//
            .withCoreSize(configuration.getThreads()))//
        .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()//
            .withExecutionTimeoutInMilliseconds(configuration.getTimeout())));
    this.parameters = parameters;
    this.type = type;
}
 
Example #17
Source File: PaymentRestHacksControllerV3.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution ctx) throws Exception {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = (long) ctx.getVariable("amount");

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
        return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  ctx.setVariable("paymentTransactionId", response.transactionId);
}
 
Example #18
Source File: TestCommandKey.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Test
public void testToHystrixCommandGroupKey() {
  Invocation invocation = Mockito.mock(Invocation.class);

  Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
  Mockito.when(invocation.getOperationMeta().getMicroserviceQualifiedName()).thenReturn("test1");
  Assert.assertNotNull(invocation);
  HystrixCommandGroupKey hystrixCommandGroupKey = CommandKey.toHystrixCommandGroupKey("groupname", invocation);
  Assert.assertNotNull(hystrixCommandGroupKey);
}
 
Example #19
Source File: PaymentRestHacksControllerV4.java    From flowing-retail with Apache License 2.0 5 votes vote down vote up
public void execute(DelegateExecution ctx) throws Exception {
  CreateChargeRequest request = new CreateChargeRequest();
  request.amount = (long) ctx.getVariable("amount");

  CreateChargeResponse response = new HystrixCommand<CreateChargeResponse>(HystrixCommandGroupKey.Factory.asKey("stripe")) {
    protected CreateChargeResponse run() throws Exception {
      return rest.postForObject( //
          stripeChargeUrl, //
          request, //
          CreateChargeResponse.class);
    }
  }.execute();
  
  ctx.setVariable("paymentTransactionId", response.transactionId);
}
 
Example #20
Source File: HelloCommand.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public HelloCommand(String name) {
	super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ThreadPoolTestGroup"))
			.andCommandKey(HystrixCommandKey.Factory.asKey("testCommandKey"))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(name))
			.andCommandPropertiesDefaults(
					HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(20000))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withMaxQueueSize(5) // 配置队列大小
					.withCoreSize(2) // 配置线程池里的线程数
	));
}
 
Example #21
Source File: MessageInvokeCommandForThreadIsolation.java    From pmq with Apache License 2.0 5 votes vote down vote up
public MessageInvokeCommandForThreadIsolation(String consumerGroupName, ConsumerQueueDto pre, List<MessageDto> dtos,
		ISubscriber iSubscriber) {
	super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(consumerGroupName))
			.andCommandKey(HystrixCommandKey.Factory.asKey(consumerGroupName + "." + pre.getOriginTopicName()))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(consumerGroupName + "." + pre.getQueueId()))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(pre.getThreadSize()))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
					// .withExecutionTimeoutInMilliseconds(pre.getTimeout() * 1000)
					.withExecutionTimeoutEnabled(true)
					.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD)
					.withCircuitBreakerEnabled(false)));
	this.iSubscriber1 = iSubscriber;
	this.pre1 = pre;
	this.dtos = dtos;		
}
 
Example #22
Source File: CommandUsingSemaphoreIsolation.java    From tools-journey with Apache License 2.0 5 votes vote down vote up
public CommandUsingSemaphoreIsolation(int id) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ExampleGroup"))
            // since we're doing work in the run() method that doesn't involve network traffic
            // and executes very fast with low risk we choose SEMAPHORE isolation
            .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
                    .withExecutionIsolationStrategy(ExecutionIsolationStrategy.SEMAPHORE)));
    this.id = id;
}
 
Example #23
Source File: HelloSemphor.java    From TakinRPC with Apache License 2.0 5 votes vote down vote up
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(20).withKeepAliveTimeMinutes(5).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(100);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)//
                    .withExecutionIsolationSemaphoreMaxConcurrentRequests(10);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
Example #24
Source File: TakinHystrixCommand.java    From TakinRPC with Apache License 2.0 5 votes vote down vote up
public TakinHystrixCommand(RemotingContext context) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(context.getProtocol().getDefineClass().getName()))//
                    .andCommandKey(HystrixCommandKey.Factory.asKey(//
                                    String.format("%s_%d", context.getProtocol().getMethod(), context.getProtocol().getArgs() == null ? 0 : context.getProtocol().getArgs().length)))//
                    .andCommandPropertiesDefaults(HystrixCommandProperties.Setter()//
                                    .withCircuitBreakerRequestVolumeThreshold(20)//10秒钟内至少19此请求失败,熔断器才发挥起作用
                                    .withCircuitBreakerSleepWindowInMilliseconds(30000)//熔断器中断请求30秒后会进入半打开状态,放部分流量过去重试
                                    .withCircuitBreakerErrorThresholdPercentage(50)//错误率达到50开启熔断保护
                                    .withExecutionTimeoutEnabled(false))//使用dubbo的超时,禁用这里的超时
                    .andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(DEFAULT_THREADPOOL_CORE_SIZE)));//线程池为30
    this.context = context;
    logger.info("use TakinHystrixCommand");
}
 
Example #25
Source File: CustommerCommand.java    From resilient-transport-service with Apache License 2.0 5 votes vote down vote up
public CustommerCommand(Long custommerId, RestTemplate restTemplate, boolean secondTry) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("CustomerServiceClientGroup"))
        .andCommandKey(HystrixCommandKey.Factory.asKey("CustomerServiceClient")));
    this.custommerId = custommerId;
    this.restTemplate = restTemplate;

    this.secondTry = secondTry;
}
 
Example #26
Source File: HelloCommand.java    From TakinRPC with Apache License 2.0 5 votes vote down vote up
private static Setter setter() {
    HystrixCommandGroupKey groupkey = HystrixCommandGroupKey.Factory.asKey("rpc");
    HystrixCommandKey commandkey = HystrixCommandKey.Factory.asKey("say");
    HystrixThreadPoolKey threadpoolkey = HystrixThreadPoolKey.Factory.asKey("hello-1");
    HystrixThreadPoolProperties.Setter threadproperties = HystrixThreadPoolProperties.Setter()//
                    .withCoreSize(1).withKeepAliveTimeMinutes(1).withMaxQueueSize(1000).withQueueSizeRejectionThreshold(2);

    HystrixCommandProperties.Setter commandproperty = HystrixCommandProperties.Setter()//
                    .withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.THREAD);
    return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
                    .andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
                    .andCommandPropertiesDefaults(commandproperty);
}
 
Example #27
Source File: CommandGetHorsesInRaceWithCaching.java    From hystrix_lab with MIT License 5 votes vote down vote up
/**
 * CommandGetHorsesInRaceWithCaching.
 * @param service
 *            Remote Broker Service
 * @param raceCourseId
 *            Id of race course
 */
public CommandGetHorsesInRaceWithCaching(BettingService service, String raceCourseId) {
	super(Setter.withGroupKey(
			HystrixCommandGroupKey.Factory.asKey("BettingServiceGroup"))
			.andThreadPoolKey(
					HystrixThreadPoolKey.Factory.asKey("BettingServicePool")));
	
	this.service = service;
	this.raceCourseId = raceCourseId;
}
 
Example #28
Source File: GetOrderCommand.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GetOrderCommand(String name) {
	super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("ThreadPoolTestGroup"))
			.andCommandKey(HystrixCommandKey.Factory.asKey("testCommandKey"))
			.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(name))
			.andCommandPropertiesDefaults(
					HystrixCommandProperties.Setter().withExecutionTimeoutInMilliseconds(20000))
			.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withMaxQueueSize(5) // 配置队列大小
					.withCoreSize(2) // 配置线程池里的线程数
	));
}
 
Example #29
Source File: GetOrderCommandSemaphore.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public GetOrderCommandSemaphore(String name) {
	// 设置信号量隔离策略
	super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("GetCityNameGroup"))
			.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
					.withExecutionIsolationStrategy(HystrixCommandProperties.ExecutionIsolationStrategy.SEMAPHORE)
					.withExecutionIsolationSemaphoreMaxConcurrentRequests(8)));
}
 
Example #30
Source File: AddressCommand.java    From resilient-transport-service with Apache License 2.0 5 votes vote down vote up
public AddressCommand(AddressDTO addressDTO, RestTemplate restTemplate, boolean secondTry) {
    super(Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("AddressServiceClientGroup"))
        .andCommandKey(HystrixCommandKey.Factory.asKey("AddressServiceClient")));

    this.addressDTO = addressDTO;
    this.restTemplate = restTemplate;
    this.secondTry = secondTry;
}