当前位置: 首页>>代码示例>>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;未经允许,请勿转载。