Skip to content

Instantly share code, notes, and snippets.

@chocotan
Created November 17, 2016 01:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chocotan/fe754204d8af39dfaf72faaf0f198edb to your computer and use it in GitHub Desktop.
Save chocotan/fe754204d8af39dfaf72faaf0f198edb to your computer and use it in GitHub Desktop.
//原来的业务代码:
return yourService.exec(params);
//改成:
return new ServiceCommand(yourService, params).execute();
public class ServiceCommand extends HystrixCommand{
yourService;
params;
HystrixThreadPoolProperties.Setter A系统setter = HystrixThreadPoolProperties.Setter().withCoreSize(50).withMaxQueueSize(200).withQueueSizeRejectionThreshold(50);
HystrixCommandProperties.Setter A系统commandSetter = HystrixCommandProperties.Setter()
.withCircuitBreakerForceClosed(true).withExecutionTimeoutInMilliseconds(3000).withExecutionIsolationSemaphoreMaxConcurrentRequests(50);
B系统setter
B系统commandSetter
...
public ServiceCommand(yourService, params){
super(
Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(系统号))
.andCommandKey(HystrixCommandKey.Factory.asKey(系统号))
.andThreadPoolPropertiesDefaults(该系统对应的线程池配置)
.andCommandPropertiesDefaults(该系统对应的command配置)
);
this.yourService = yourService;
this.params = params;
}
@Override
protected Object run() {
return yourService.exec(params);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment