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


Java HystrixCommandGroupKey類代碼示例

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


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

示例1: bottle

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的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();
}
 
開發者ID:spring-cloud-samples,項目名稱:brewery,代碼行數:24,代碼來源:Bottler.java

示例2: commandKeyIsRequestLineSetterFactory

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

示例3: setter

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

示例4: setter

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

示例5: GrpcHystrixCommand

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

示例6: create

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的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));
}
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:9,代碼來源:SetterFactory.java

示例7: customSetter

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的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();
  }
 
開發者ID:wenwu315,項目名稱:XXXX,代碼行數:22,代碼來源:SetterFactoryTest.java

示例8: DubboHystrixCommand

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

示例9: chargeCreditCard

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的package包/類
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;
}
 
開發者ID:flowing,項目名稱:flowing-retail,代碼行數:17,代碼來源:PaymentRestHacksControllerV2.java

示例10: DubboHystrixCommand

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

示例11: HelloWorldCommand3

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

示例12: getCommandSetter

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

示例13: should_pass_tracing_information_when_using_Hystrix_commands

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的package包/類
@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
	Tracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
			new DefaultSpanNamer(), new NoOpSpanLogger(), new NoOpSpanReporter());
	TraceKeys traceKeys = new TraceKeys();
	HystrixCommand.Setter setter = HystrixCommand.Setter
			.withGroupKey(HystrixCommandGroupKey.Factory.asKey("group"))
			.andCommandKey(HystrixCommandKey.Factory.asKey("command"));
	// tag::hystrix_command[]
	HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
		@Override
		protected String run() throws Exception {
			return someLogic();
		}
	};
	// end::hystrix_command[]
	// tag::trace_hystrix_command[]
	TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
		@Override
		public String doRun() throws Exception {
			return someLogic();
		}
	};
	// end::trace_hystrix_command[]

	String resultFromHystrixCommand = hystrixCommand.execute();
	String resultFromTraceCommand = traceCommand.execute();

	then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
	then(tracer.getCurrentSpan()).isNull();
}
 
開發者ID:reshmik,項目名稱:Zipkin,代碼行數:32,代碼來源:TraceCommandTests.java

示例14: HystrixProcessor

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的package包/類
public HystrixProcessor(HystrixCommandGroupKey groupKey, HystrixCommandKey commandKey, HystrixCommandKey fallbackCommandKey,
                        HystrixCommand.Setter setter, HystrixCommand.Setter fallbackSetter,
                        Processor processor, Processor fallback, boolean fallbackViaNetwork) {
    this.groupKey = groupKey;
    this.commandKey = commandKey;
    this.fallbackCommandKey = fallbackCommandKey;
    this.setter = setter;
    this.fallbackSetter = fallbackSetter;
    this.processor = processor;
    this.fallback = fallback;
    this.fallbackViaNetwork = fallbackViaNetwork;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:13,代碼來源:HystrixProcessor.java

示例15: MongoFindCommand

import com.netflix.hystrix.HystrixCommandGroupKey; //導入依賴的package包/類
/**
 * Create a command to execute a Find.
 *
 * @param db the DB object
 * @param collectionName name of collection
 * @param search search object
 * @param jsonProjection projection if want subset of results
 * @param limit number of objects to return, less than 0 indicates all
 * @param converter converter implementation to use
 * @param clazz the Class of object finding
 */
public MongoFindCommand(DB db, String collectionName, Object search, String jsonProjection,
                        int limit, Converter converter, Class<T> clazz) {
    super(HystrixCommand.Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("MongoFind"))
            .andCommandKey(HystrixCommandKey.Factory.asKey("MongoFind"))
    );

    this.db = db;
    this.collectionName = collectionName;
    this.search = search;
    this.jsonQuery = null;
    this.jsonProjection = jsonProjection;
    this.limit = limit;
    this.converter = converter;
    this.clazz = clazz;
}
 
開發者ID:jewzaam,項目名稱:mongo-utility,代碼行數:27,代碼來源:MongoFindCommand.java


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