Java HystrixProperty类代码示例(javahystrixproperty类代码示例汇总)

本文整理汇总了Java中com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty的典型用法代码示例。如果您正苦于以下问题:Java HystrixProperty类的具体用法?Java HystrixProperty怎么用?Java HystrixProperty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Java HystrixProperty类代码示例(javahystrixproperty类代码示例汇总)

HystrixProperty类属于com.netflix.hystrix.contrib.javanica.annotation包,在下文中一共展示了HystrixProperty类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: callCircuitBreaker

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "callCircuitBreakerFailback", commandKey = "circuitBreakerKey", commandProperties = {
        @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"), // 请求总数下限
        @HystrixProperty(name = "circuitBreaker.errorThresholdPercentage", value = "20"), // 错误百分比下限
        @HystrixProperty(name = "circuitBreaker.sleepWindowInMilliseconds", value = "5000") }) // 休眠时间窗
public String callCircuitBreaker() {
    System.out.println("callCircuitBreaker 主逻辑");
    return restTemplate.getForEntity("http://client/circuitBreaker", String.class).getBody();
} 
开发者ID:yangdd1205,项目名称:spring-cloud-master,代码行数:9,代码来源:HelloService.java

示例2: getCostCenter

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "getFallbackCostCenter",
        commandProperties = {
                @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "5")})
public CostCenterTO getCostCenter(int number) {
    ResponseEntity<List<CostCenterTO>> exchange = restTemplate.exchange(
            url + "/costcenter?number=" + number,
            HttpMethod.GET,
            null,
            new ParameterizedTypeReference<List<CostCenterTO>>() {
            });

    if (!exchange.getBody().isEmpty())
        return exchange.getBody().iterator().next();
    else
        return null;
} 
开发者ID:microservices-demos,项目名称:resilience-demo,代码行数:18,代码来源:CostCenterProxyImpl.java

示例3: invokeRemoteHystrixService

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "defaultInvokeRemoteHystrixService", 
	groupKey = "micro-service-netflix-gateway.GatewayGroup", 
	commandKey = "micro-service-netflix-gateway.GatewayService.invokeRemoteHystrixService", 
	threadPoolKey = "micro-service-netflix-gateway.GatewayThreadPool", 	
	commandProperties = {
	@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000") 
})
public String invokeRemoteHystrixService() {
	
	InstanceInfo instance = discoveryClient.getNextServerFromEureka("micro-service-netflix-server", false);
	logger.info("invoke remote service micro-service-netflix-server by native eureka client, ##### {} #####", instance.getHomePageUrl());
	
	InstanceInfo instance2 = discoveryClient.getNextServerFromEureka("micro-service-netflix-server2", false);
	logger.info("invoke remote service micro-service-netflix-server2 by native eureka client, ##### {} #####", instance2.getHomePageUrl());
	
	return "invokeRemoteHystrixService";
} 
开发者ID:colddew,项目名称:micro-service-netflix,代码行数:18,代码来源:GatewayService.java

示例4: getFilmById

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(
        fallbackMethod = "getFilmByIdFailure",
        //all options here: https://github.com/Netflix/Hystrix/wiki/Configuration
        commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "100")
        },
        threadPoolProperties = {
            @HystrixProperty(name = "coreSize", value = "5"), // the maximum number of HystrixCommands that can execute concurrently. Default 10
            @HystrixProperty(name = "maxQueueSize", value = "101"), //If -1 then SynchronousQueue will be used, otherwise a positive value will be used with LinkedBlockingQueue.
            @HystrixProperty(name = "metrics.healthSnapshot.intervalInMilliseconds", value = "15") //time to wait, between allowing health snapshots to be taken that calculate success and error percentages and affect circuit breaker status.
        })
public Optional<Film> getFilmById(final Long filmId) { //this could return Future or ObservableResult, to use it async, not waste resources, and make it explicit that it takes long
    ResponseEntity<Film> responseEntity = filmCatalogueClient.findOne(filmId);
    if(responseEntity.getStatusCode() != HttpStatus.OK) {
        return Optional.empty();
    }
    return Optional.of(responseEntity.getBody());
} 
开发者ID:jakubnabrdalik,项目名称:hentai-cloudy-rental,代码行数:19,代码来源:FilmCatalogueClientWithHystrix.java

示例5: gnomesData

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "defaultValue",
        commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000"),
                @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE")
        })
public Observable<Map<String,Double>> gnomesData(){

   return new ObservableResult<Map<String, Double>>() {
       @Override
       public Map<String, Double> invoke() {
           Map<String,Double> response = template.getForObject("http://gnomes-data/data",Map.class, Collections.singletonMap("base",10));
           Double data = response.get("data");
           lastValue = data;
           return Collections.singletonMap("gnomes",data);
       }
   };


} 
开发者ID:viniciusccarvalho,项目名称:gnomes-demo,代码行数:20,代码来源:GnomesClient.java

示例6: profitData

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "defaultValue",
        commandProperties = {
                @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000"),
                @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE")
        })
public Observable<Map<String,Double>> profitData(){
    return new ObservableResult<Map<String, Double>>() {
        @Override
        public Map<String, Double> invoke() {
            Map<String,Double> response = template.getForObject("http://gnomes-data/data?base={base}",Map.class, 100);
            Double data = response.get("data");
            lastValue = data;
            return Collections.singletonMap("profit",data);
        }
    };
} 
开发者ID:viniciusccarvalho,项目名称:gnomes-demo,代码行数:17,代码来源:ProfitClient.java

示例7: getQuotes

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
/**
 * Retrieve one or more quotes.
 *
 * @param symbols comma delimited list of symbols.
 * @return a list of quotes.
 */
@HystrixCommand(fallbackMethod = "getMarkitondemandQuotes",
        commandProperties = {@HystrixProperty(name="execution.timeout.enabled", value="false")})
public List<Quote> getQuotes(String symbols) throws SymbolNotFoundException {
    logger.debug("retrieving quotes for: " + symbols);
    if ( symbols.isEmpty() ) return new ArrayList<>();

    YahooQuoteResponses responses = restTemplate.getForObject(yahoo_url, YahooQuoteResponses.class, symbols, FMT, ENV);
    logger.debug("Got responses: " + responses);
    List<YahooQuote> yahooQuotes = responses.getResults().getQuoteList().getQuote();
    Date createDate = responses.getResults().getCreated();

    List<Quote> quotes = yahooQuotes
            .stream()
            .map(yQuote -> QuoteMapper.INSTANCE.mapFromYahooQuote(yQuote, createDate))
            .collect(Collectors.toList());

    for (Quote quote : quotes) {
        if ( quote.getName() == null ) throw new SymbolNotFoundException( quote.getSymbol() + " not found" );
    }
    return quotes;
} 
开发者ID:dpinto-pivotal,项目名称:cf-SpringBootTrader,代码行数:28,代码来源:QuoteService.java

示例8: getMarkitondemandQuotes

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
/**
 * Retrieves an up to date quote for the given symbol.
 * 
 * @param symbols Array of symbols to retrieve quotes for.
 * @return The quote object or null if not found.
 * @throws SymbolNotFoundException
 */
@HystrixCommand(fallbackMethod = "getQuotesFallback",
           commandProperties = {@HystrixProperty(name="execution.timeout.enabled", value="false")})
   @SuppressWarnings("unused")
public List<Quote> getMarkitondemandQuotes(String symbols) throws SymbolNotFoundException {
       List<Quote> result = new ArrayList<>();
       String[] splitSymbols = symbols.split(",");

       for (String symbol : splitSymbols) {
           logger.debug("QuoteService.getQuote: retrieving quote for: " + symbol);
           Map<String, String> params = new HashMap<>();
           params.put("symbol", symbol);

           Quote quote = restTemplate.getForObject(quote_url, Quote.class, params);
           logger.debug("QuoteService.getQuote: retrieved quote: " + quote);
           result.add(quote);

           if (quote.getSymbol() == null) {
               throw new SymbolNotFoundException("Symbol not found: " + symbol);
           }
       }

	return result;
} 
开发者ID:dpinto-pivotal,项目名称:cf-SpringBootTrader,代码行数:31,代码来源:QuoteService.java

示例9: findAll

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "getItemsCache", commandProperties = {
		@HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "2") })
public Collection<Item> findAll() {
	PagedResources<Item> pagedResources = restTemplate.getForObject(catalogURL(), ItemPagedResources.class);
	this.itemsCache = pagedResources.getContent();
	return pagedResources.getContent();
} 
开发者ID:ewolff,项目名称:microservice-cloudfoundry,代码行数:8,代码来源:CatalogClient.java

示例10: getAllProducts

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "fallbackProducts",
        commandProperties = {
                @HystrixProperty(name="execution.isolation.strategy", value="SEMAPHORE")
        })
public Collection<Product> getAllProducts() {

    ResponseEntity<Product[]> response = template.getForEntity(
            "http://localhost:8080/products", Product[].class);

    return Arrays.asList(response.getBody());
} 
开发者ID:andifalk,项目名称:cloud-security-workshop,代码行数:12,代码来源:ProductService.java

示例11: apply

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "accountActivatedFallback", commandProperties = {
        @HystrixProperty(name = EXECUTION_TIMEOUT_ENABLED, value = "false")
})
public LambdaResponse<Account> apply(AccountEvent accountEvent) {
    try {
        return new LambdaResponse<>(functionService.accountActivated(accountEvent));
    } catch (Exception ex) {
        if (Objects.equals(ex.getMessage(), "Account already activated")) {
            return new LambdaResponse<>(ex, null);
        } else {
            log.error("Error invoking AWS Lambda function", ex);
            throw ex;
        }
    }
} 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:16,代码来源:ActivateAccount.java

示例12: apply

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@HystrixCommand(fallbackMethod = "accountSuspendedFallback", commandProperties = {
        @HystrixProperty(name = EXECUTION_TIMEOUT_ENABLED, value = "false")
})
public LambdaResponse<Account> apply(AccountEvent accountEvent) {
    try {
        return new LambdaResponse<>(functionService.accountSuspended(accountEvent));
    } catch (Exception ex) {
        if (Objects.equals(ex.getMessage(), "Account already suspended")) {
            return new LambdaResponse<>(ex, null);
        } else {
            log.error("Error invoking AWS Lambda function", ex);
            throw ex;
        }
    }
} 
开发者ID:kbastani,项目名称:service-block-samples,代码行数:16,代码来源:SuspendAccount.java

示例13: addEmailToQueue

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@Override
@HystrixCommand(fallbackMethod = "errorOnAddEmailToQueue", commandProperties = { @HystrixProperty(name = "execution.isolation.strategy", value = "SEMAPHORE") })
public Boolean addEmailToQueue(final AitTaskEmailPivotVO email) {
	AitLogger.debug(logger, "Trying to add email to the Queue: {}", email.getEmailTo());
	try {
		return client.addEmailToQueue(email).getBody();
	} catch (final Exception e) {
		e.printStackTrace();
		return errorOnAddEmailToQueue(email);
	}
} 
开发者ID:allianzit,项目名称:ait-platform,代码行数:12,代码来源:AitCommonRetriever.java

示例14: search

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
@Override
@HystrixCommand(commandKey = "GetTweets", fallbackMethod = "noResults", commandProperties = {
        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
})
public Collection<String> search(String q, int pageSize) {
    SearchResults results = twitter.searchOperations().search(q, pageSize);
    return results.getTweets().stream()
            .map(Tweet::getUnmodifiedText)
            .collect(toSet());
} 
开发者ID:qaware,项目名称:hitchhikers-guide-cloudnative,代码行数:11,代码来源:ZwitscherRepositoryImpl.java

示例15: findByQ

import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty; //导入依赖的package包/类
/**
 * Find the matching Zwitscher messages for the given query.
 *
 * @param q the query, max 500 chars long
 * @return the tweets, never NULL
 */
@HystrixCommand(commandKey = "FindByQ", fallbackMethod = "none", commandProperties = {
        @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
})
public Collection<String> findByQ(final @Length(max = 500) String q) {
    log.info("Get Zwitscher message from /tweets using q={}.", q);

    String[] tweets = restTemplate.getForObject(tweetsRibbonUrl, String[].class, q);
    return Arrays.asList(tweets);
} 
开发者ID:qaware,项目名称:hitchhikers-guide-cloudnative,代码行数:16,代码来源:ZwitscherRepository.java

本文标签属性:

示例:示例图

代码:代码是什么

java:java自行车

HystrixProperty:HystrixProperty

上一篇:Java PreferenceScreen.getPreferenceCount方法代码示例(javapreferencescreen.getpreferencecount典型用法代码示例汇总)
下一篇:生物技术是什么(什么是生物技术)

为您推荐