當前位置: 首頁>>代碼示例>>Java>>正文


Java HystrixCommandProperties類代碼示例

本文整理匯總了Java中com.netflix.hystrix.HystrixCommandProperties的典型用法代碼示例。如果您正苦於以下問題:Java HystrixCommandProperties類的具體用法?Java HystrixCommandProperties怎麽用?Java HystrixCommandProperties使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HystrixCommandProperties類屬於com.netflix.hystrix包,在下文中一共展示了HystrixCommandProperties類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testGetCommandPropertiesCacheKey

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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

示例2: testgetCommandProperties

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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

示例3: testConstructProvider

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的package包/類
@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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:21,代碼來源:TestBizkeeperCommand.java

示例4: testGetCacheKeyWithContextInitializedProvider

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的package包/類
@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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:22,代碼來源:TestBizkeeperCommand.java

示例5: testResumeWithFallbackConsumer

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的package包/類
@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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:21,代碼來源:TestBizkeeperCommand.java

示例6: testConstructConsumer

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的package包/類
@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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:21,代碼來源:TestBizkeeperCommand.java

示例7: testGetCacheKeyWithContextInitializedConsumer

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的package包/類
@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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:22,代碼來源:TestBizkeeperCommand.java

示例8: setter

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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);
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:18,代碼來源:HelloDegrade.java

示例9: setter

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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);
}
 
開發者ID:lemonJun,項目名稱:TakinRPC,代碼行數:17,代碼來源:HelloBreaker.java

示例10: GrpcHystrixCommand

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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();
}
 
開發者ID:venus-boot,項目名稱:saluki,代碼行數:20,代碼來源:GrpcHystrixCommand.java

示例11: DubboHystrixCommand

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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;
    }
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:23,代碼來源:DubboHystrixCommand.java

示例12: DubboHystrixCommand

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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;
}
 
開發者ID:xiaomin0322,項目名稱:dubbo_plus,代碼行數:17,代碼來源:DubboHystrixCommand.java

示例13: HelloWorldCommand3

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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;
}
 
開發者ID:xiaomin0322,項目名稱:dubbo_plus,代碼行數:17,代碼來源:HelloWorldCommand3.java

示例14: getCommandSetter

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的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);
}
 
開發者ID:xiaomin0322,項目名稱:spring-integration-hystrix,代碼行數:25,代碼來源:HystrixCommandAspect.java

示例15: ManagedHystrixCommandFactory

import com.netflix.hystrix.HystrixCommandProperties; //導入依賴的package包/類
/**
 * Creates a new ManagedHystrixCommandFactory
 * @param setter the command setter
 * @param key The command key
 * @param commandPropertySetter the command property setter
 * @param threadPoolPropertySetter the thread pool property setter
 */
public ManagedHystrixCommandFactory(final Setter setter, final String key, final HystrixCommandProperties.Setter commandPropertySetter, final HystrixThreadPoolProperties.Setter threadPoolPropertySetter) {		
	this.setter = setter;
	this.key = key;
	this.commandPropertySetter = commandPropertySetter;
	this.threadPoolPropertySetter = threadPoolPropertySetter;
	final HystrixCommand<Object> sampleCommand = new HystrixCommand<Object>(setter) {
		@Override
		protected Object run() throws Exception {
			return null;
		}				
	};		
	ObjectName tmp = null;
	try {
		tmp = JMXHelper.objectName(String.format(OBJECT_NAME_TEMPLATE, sampleCommand.getCommandGroup().name(), sampleCommand.getCommandKey().name(), sampleCommand.getThreadPoolKey().name()));
	} catch (Exception ex) {
		tmp = JMXHelper.objectName(String.format(OBJECT_NAME_TEMPLATE, 
				ObjectName.quote(sampleCommand.getCommandGroup().name()), 
				ObjectName.quote(sampleCommand.getCommandKey().name()), 
				ObjectName.quote(sampleCommand.getThreadPoolKey().name())
		)); 
	}
	objectName = tmp;
}
 
開發者ID:nickman,項目名稱:HeliosStreams,代碼行數:31,代碼來源:ManagedHystrixCommandFactory.java


注:本文中的com.netflix.hystrix.HystrixCommandProperties類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。