本文整理匯總了Java中com.netflix.hystrix.HystrixCommandKey類的典型用法代碼示例。如果您正苦於以下問題:Java HystrixCommandKey類的具體用法?Java HystrixCommandKey怎麽用?Java HystrixCommandKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HystrixCommandKey類屬於com.netflix.hystrix包,在下文中一共展示了HystrixCommandKey類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: bottle
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
/**
* [SLEUTH] TraceCommand
*/
@Override
public void bottle(Wort wort, String processId, String testCommunicationType) {
log.info("I'm in the bottling service");
log.info("Process ID from headers {}", processId);
String groupKey = "bottling";
String commandKey = "bottle";
HystrixCommand.Setter setter = HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
TestConfigurationHolder testConfigurationHolder = TestConfigurationHolder.TEST_CONFIG.get();
new TraceCommand<Void>(tracer, traceKeys, setter) {
@Override
public Void doRun() throws Exception {
TestConfigurationHolder.TEST_CONFIG.set(testConfigurationHolder);
log.info("Sending info to bottling service about process id [{}]", processId);
bottlerService.bottle(wort, processId);
return null;
}
}.execute();
}
示例2: commandKeyIsRequestLineSetterFactory
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
@Bean
public SetterFactory commandKeyIsRequestLineSetterFactory() {
return new SetterFactory() {
@Override public HystrixCommand.Setter create(Target<?> target,
Method method) {
String groupKey = SETTER_PREFIX + target.name();
RequestMapping requestMapping = method
.getAnnotation(RequestMapping.class);
String commandKey =
SETTER_PREFIX + requestMapping.method()[0] + " " + requestMapping
.path()[0];
return HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
}
};
}
示例3: ExecutionIsolationStrategyHystrixProperty
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
private ExecutionIsolationStrategyHystrixProperty(ExecutionIsolationStrategy builderOverrideValue,
HystrixCommandKey key, String propertyPrefix, String command, ExecutionIsolationStrategy defaultValue,
String instanceProperty) {
this.defaultValue = defaultValue;
String overrideValue = null;
if (builderOverrideValue != null) {
overrideValue = builderOverrideValue.name();
}
property = forString()
.add(propertyPrefix + "." + command + "." + key.name() + "." + instanceProperty, null)
.add(propertyPrefix + "." + command + "." + serviceKey(key.name()) + "." + instanceProperty,
overrideValue)
.add(propertyPrefix + "." + command + "." + typeKey(key.name()) + "." + instanceProperty,
defaultValue.name())
.build();
// initialize the enum value from the property
parseProperty();
// use a callback to handle changes so we only handle the parse cost
// on updates rather than every fetch
// when the property value changes we'll update the value
property.addCallback(this::parseProperty);
}
示例4: testGetCommandPropertiesCacheKey
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
@Test
public void testGetCommandPropertiesCacheKey() {
assertNotNull(HystrixPropertiesStrategyExt.getInstance());
HystrixPropertiesStrategyExt hps = HystrixPropertiesStrategyExt.getInstance();
HystrixCommandKey commandKey = Mockito.mock(HystrixCommandKey.class);
Invocation invocation = Mockito.mock(Invocation.class);
Mockito.when(invocation.getOperationMeta()).thenReturn(Mockito.mock(OperationMeta.class));
Mockito.when(invocation.getOperationMeta().getMicroserviceName()).thenReturn("testqualify");
HystrixCommandProperties.Setter setter = HystrixCommandProperties.Setter()
.withRequestCacheEnabled(true)
.withRequestLogEnabled(false)
.withFallbackIsolationSemaphoreMaxConcurrentRequests(
Configuration.INSTANCE.getFallbackMaxConcurrentRequests("groupname",
"testing",
invocation.getOperationMeta().getMicroserviceQualifiedName()));
String str1 = hps.getCommandPropertiesCacheKey(commandKey, setter);
Assert.assertNull(str1);
}
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:TestHystrixPropertiesStrategyExt.java
示例5: testgetCommandProperties
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
@Test
public void testgetCommandProperties() {
HystrixCommandKey commandKey = Mockito.mock(HystrixCommandKey.class);
Mockito.when(commandKey.name())
.thenReturn("provider.HystrixPropertiesStrategyExtTest.testgetCommandProperties");
HystrixCommandProperties commandPro = HystrixPropertiesStrategyExt.getInstance()
.getCommandProperties(commandKey, HystrixCommandProperties.Setter());
Assert.assertTrue(commandPro.circuitBreakerEnabled().get());
Assert.assertEquals(Integer.valueOf(50), commandPro.circuitBreakerErrorThresholdPercentage().get());
Assert.assertFalse(commandPro.circuitBreakerForceClosed().get());
Assert.assertFalse(commandPro.circuitBreakerForceOpen().get());
Assert.assertEquals(Integer.valueOf(20), commandPro.circuitBreakerRequestVolumeThreshold().get());
Assert.assertEquals(Integer.valueOf(15000), commandPro.circuitBreakerSleepWindowInMilliseconds().get());
Assert.assertEquals(Integer.valueOf(1000), commandPro.executionIsolationSemaphoreMaxConcurrentRequests().get());
Assert.assertTrue(commandPro.executionIsolationThreadInterruptOnTimeout().get());
Assert.assertEquals(null, commandPro.executionIsolationThreadPoolKeyOverride().get());
Assert.assertEquals(Integer.valueOf(30000), commandPro.executionTimeoutInMilliseconds().get());
Assert.assertFalse(commandPro.executionTimeoutEnabled().get());
Assert.assertEquals(Integer.valueOf(10), commandPro.fallbackIsolationSemaphoreMaxConcurrentRequests().get());
Assert.assertTrue(commandPro.fallbackEnabled().get());
Assert.assertEquals(Integer.valueOf(100), commandPro.metricsRollingPercentileBucketSize().get());
Assert.assertFalse(commandPro.metricsRollingPercentileEnabled().get());
}
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:24,代碼來源:TestHystrixPropertiesStrategyExt.java
示例6: setter
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
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);
}
示例7: setter
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
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()//
.withCircuitBreakerEnabled(true).withCircuitBreakerForceClosed(false)//
.withCircuitBreakerForceOpen(false).withCircuitBreakerErrorThresholdPercentage(50)//
.withCircuitBreakerRequestVolumeThreshold(20)//
.withCircuitBreakerSleepWindowInMilliseconds(5000);
return HystrixCommand.Setter.withGroupKey(groupkey).andCommandKey(commandkey)//
.andThreadPoolKey(threadpoolkey).andThreadPoolPropertiesDefaults(threadproperties)//
.andCommandPropertiesDefaults(commandproperty);
}
示例8: GrpcHystrixCommand
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
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();
}
示例9: create
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
@Override
public HystrixCommand.Setter create(Target<?> target, Method method) {
String groupKey = target.name();
String commandKey = Feign.configKey(target.type(), method);
return HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
}
示例10: customSetter
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
@Test
public void customSetter() {
thrown.expect(HystrixRuntimeException.class);
thrown.expectMessage("POST / failed and no fallback available.");
server.enqueue(new MockResponse().setResponseCode(500));
SetterFactory commandKeyIsRequestLine = (target, method) -> {
String groupKey = target.name();
String commandKey = method.getAnnotation(RequestLine.class).value();
return HystrixCommand.Setter
.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
};
TestInterface api = HystrixFeign.builder()
.setterFactory(commandKeyIsRequestLine)
.target(TestInterface.class, "http://localhost:" + server.getPort());
api.invoke();
}
示例11: DubboHystrixCommand
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
public DubboHystrixCommand(Invoker<?> invoker, final Invocation invocation, final Map<String,String> hystrixMap){
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()
//10秒鍾內至少19次請求失敗,熔斷器才發揮起作用
.withCircuitBreakerRequestVolumeThreshold(Integer.parseInt(hystrixMap.get("requestVolume")))
//熔斷器中斷請求30秒後會進入半打開狀態,放部分流量過去重試
.withCircuitBreakerSleepWindowInMilliseconds(Integer.parseInt(hystrixMap.get("sleepMilliseconds")))
//錯誤率達到50開啟熔斷保護
.withCircuitBreakerErrorThresholdPercentage(Integer.parseInt(hystrixMap.get("errorPercentage")))
//使用dubbo的超時,禁用這裏的超時
.withExecutionTimeoutEnabled(Boolean.valueOf(hystrixMap.get("executionTimeoutEnabled"))))
//線程池為30
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(getThreadPoolCoreSize(invoker.getUrl()))));
this.invoker=invoker;
this.invocation=invocation;
}
示例12: HystrixObservableContent
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
private HystrixObservableContent(final Observable<Content> observable,
final Observable<Content> fallback,
final Ref commandKey,
final int timeoutMillis) {
super(Setter.withGroupKey(asKey(commandKey.name()))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey.name()))
.andCommandPropertiesDefaults(Setter()
.withExecutionIsolationStrategy(SEMAPHORE)
// this configures the max number of concurrent requests per command:
// TODO: make it easier to use different commands (one per service)
// TODO: make this value configurable
.withExecutionIsolationSemaphoreMaxConcurrentRequests(MAX_CONCURRENT_REQUESTS_PER_COMMANDKEY)
.withExecutionTimeoutInMilliseconds(timeoutMillis)
)
);
this.observable = observable;
this.fallback = fallback;
}
示例13: DubboHystrixCommand
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
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(invoker.getUrl().getParameter("circuitBreakerRequestVolumeThreshold", circuitBreakerRequestVolumeThreshold))//10秒鍾內至少19此請求失敗,熔斷器才發揮起作用
.withCircuitBreakerSleepWindowInMilliseconds(invoker.getUrl().getParameter("circuitBreakerSleepWindowInMilliseconds",circuitBreakerSleepWindowInMilliseconds))//熔斷器中斷請求30秒後會進入半打開狀態,放部分流量過去重試
.withCircuitBreakerErrorThresholdPercentage(invoker.getUrl().getParameter("circuitBreakerErrorThresholdPercentage",circuitBreakerErrorThresholdPercentage))//錯誤率達到50開啟熔斷保護
.withExecutionTimeoutEnabled(false))//使用dubbo的超時,禁用這裏的超時
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(invoker.getUrl().getParameter("coreSize",coreSize))));//線程池為30
this.invoker=invoker;
this.invocation=invocation;
}
示例14: HelloWorldCommand3
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
public HelloWorldCommand3(String name) {
super(
Setter.withGroupKey(
HystrixCommandGroupKey.Factory.asKey("HelloWorldGroup"))
.andCommandKey(HystrixCommandKey.Factory.asKey("HelloWorldKey"))
.andCommandPropertiesDefaults(HystrixCommandProperties.Setter()
//實行超時
.withExecutionIsolationThreadTimeoutInMilliseconds(
5000)
.withCircuitBreakerRequestVolumeThreshold(2)//10秒鍾內至少2此請求失敗,熔斷器才發揮起作用
.withCircuitBreakerSleepWindowInMilliseconds(3000)//熔斷器中斷請求30秒後會進入半打開狀態,放部分流量過去重試
.withCircuitBreakerErrorThresholdPercentage(50)//錯誤率達到50開啟熔斷保護
.withExecutionTimeoutEnabled(false))//使用dubbo的超時,禁用這裏的超時
.andThreadPoolPropertiesDefaults(HystrixThreadPoolProperties.Setter().withCoreSize(3)));//線程池為30
this.name = name;
}
示例15: getCommandSetter
import com.netflix.hystrix.HystrixCommandKey; //導入依賴的package包/類
/**
* ��·������ �ο� http://hot66hot.iteye.com/blog/2155036
*
* @param joinPoint
* @param cb
* @return
*/
private HystrixCommand.Setter getCommandSetter(ProceedingJoinPoint joinPoint,
com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand cb) {
String name = getHystrixGroupName(joinPoint, cb);
String groupKey = StringUtils.isEmpty(cb.groupKey()) ? name : cb.groupKey();
String commandKey = StringUtils.isEmpty(cb.commandKey()) ? name : cb.commandKey();
HystrixThreadPoolKey hystrixThreadPoolKey = StringUtils.isEmpty(cb.threadPoolKey()) ? null
: HystrixThreadPoolKey.Factory.asKey(cb.threadPoolKey());
HystrixCommandProperties.Setter commandPropertiesDefaults = getHystrixCommandPropertiesSetter(cb);
HystrixThreadPoolProperties.Setter threadPoolPropertiesDefaults = getHystrixThreadPoolPropertiesSetter(cb);
return HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey(groupKey))
.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey)).andThreadPoolKey(hystrixThreadPoolKey)
.andCommandPropertiesDefaults(commandPropertiesDefaults)
.andThreadPoolPropertiesDefaults(threadPoolPropertiesDefaults);
}