当前位置: 首页>>代码示例>>Java>>正文


Java IClientConfig类代码示例

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


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

示例1: zoneAffinity

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
/**
 * Zone affinity rule.
 *
 * @param clientConfig the ribbon client config.
 * @param rule         the predicate rule support
 * @return the zone affinity rule.
 */
@Bean
public CompositePredicate zoneAffinity(IClientConfig clientConfig, PredicateBasedRuleSupport rule) {
    AvailabilityPredicate availabilityPredicate = new AvailabilityPredicate(rule, clientConfig);
    ZoneAvoidancePredicate zoneAvoidancePredicate = new ZoneAvoidancePredicate(rule, clientConfig);
    ZoneAffinityMatcher zoneAffinityMatcher = new ZoneAffinityMatcher(getEurekaInstanceProperties().getZone());
    CompositePredicate predicate = withPredicates(zoneAffinityMatcher)
            .addFallbackPredicate(withPredicates(zoneAvoidancePredicate, availabilityPredicate).build())
            .addFallbackPredicate(availabilityPredicate)
            .addFallbackPredicate(alwaysTrue())
            .build();
    rule.setPredicate(predicate);
    rule.setDescription(from(zoneAffinityMatcher)
            .fallback(from("ZoneAvoidance").and(from("Availability")))
            .fallback(from("Availability"))
            .fallback(from("Any()")));
    log.info("Zone affinity enabled for client [{}].", clientConfig.getClientName());
    return predicate;
}
 
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:26,代码来源:ZoneAffinityConfig.java

示例2: favoriteZone

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
/**
 * Favorite zone rule bean.
 *
 * @param clientConfig the ribbon client config
 * @param rule         the predicate rule support
 * @return the favorite zone rule
 */
@Bean
public CompositePredicate favoriteZone(IClientConfig clientConfig, PredicateBasedRuleSupport rule) {
    AvailabilityPredicate availabilityPredicate = new AvailabilityPredicate(rule, clientConfig);
    ZoneAvoidancePredicate zoneAvoidancePredicate = new ZoneAvoidancePredicate(rule, clientConfig);
    ZoneAffinityMatcher zoneAffinityMatcher = new ZoneAffinityMatcher(getEurekaInstanceProperties().getZone());
    DynamicZoneMatcher dynamicZoneMatcher = new DynamicZoneMatcher(favoriteZoneKey);
    DynamicZoneMatcher upstreamZoneMatcher = new DynamicZoneMatcher(upstreamZoneKey);
    CompositePredicate predicate = withPredicates(dynamicZoneMatcher)
            .addFallbackPredicate(zoneAffinityMatcher)
            .addFallbackPredicate(upstreamZoneMatcher)
            .addFallbackPredicate(withPredicates(zoneAvoidancePredicate, availabilityPredicate).build())
            .addFallbackPredicate(availabilityPredicate)
            .addFallbackPredicate(alwaysTrue())
            .build();
    rule.setPredicate(predicate);
    rule.setDescription(from(dynamicZoneMatcher)
            .fallback(from(zoneAffinityMatcher))
            .fallback(from(upstreamZoneMatcher))
            .fallback(from("ZoneAvoidance").and(from("Availability")))
            .fallback(from("Availability"))
            .fallback(from("any()")));
    log.info("Favorite zone enabled for client [{}] using context key [{}].", clientConfig.getClientName(), favoriteZoneKey);
    return predicate;
}
 
开发者ID:enadim,项目名称:spring-cloud-ribbon-extensions,代码行数:32,代码来源:FavoriteZoneConfig.java

示例3: getRequestSpecificRetryHandler

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Override
public RequestSpecificRetryHandler getRequestSpecificRetryHandler(
    RibbonRequest request, IClientConfig requestConfig) {
  if (clientConfig.get(CommonClientConfigKey.OkToRetryOnAllOperations, false)) {
    return new RequestSpecificRetryHandler(true, true, this.getRetryHandler(), requestConfig);
  }
  if (!request.toRequest().method().equals("GET")) {
    return new RequestSpecificRetryHandler(true, false, this.getRetryHandler(), requestConfig);
  } else {
    return new RequestSpecificRetryHandler(true, true, this.getRetryHandler(), requestConfig);
  }
}
 
开发者ID:wenwu315,项目名称:XXXX,代码行数:13,代码来源:LBClient.java

示例4: execute

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Override
public RibbonResponse execute(RibbonRequest request, IClientConfig requestConfig) throws Exception {
	try {
		HttpClientRequest ribbonHttpRequestMessage = httpClientRequestFactory.createOf(request.replaceUri());

		request.writeTo(ribbonHttpRequestMessage);

		HttpResponseMessage httpResponse = ribbonHttpRequestMessage.execute();

		return new RibbonResponse(httpResponse);

	} catch (Exception e) {
		ribbonExceptionHandler.onException(request, e);
		throw e;
	}
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:17,代码来源:RibbonLoadBalancedClient.java

示例5: setup

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Before
public void setup() {
	ILoadBalancer loadBalancer = new BaseLoadBalancer();
	loadBalancer.addServers(Arrays.asList(new Server("localhost", 7080)));
	loadBalancer.addServers(Arrays.asList(new Server("localhost", 7081)));
	loadBalancer.addServers(Arrays.asList(new Server("localhost", 7082)));

	IClientConfig clientConfig = new DefaultClientConfigImpl();

	RibbonHttpClientRequestFactory ribbonHttpClientRequestFactory = new RibbonHttpClientRequestFactory(loadBalancer, clientConfig);

	myApi = new RestifyProxyBuilder()
			.client(ribbonHttpClientRequestFactory)
			.target(MyApi.class, "http://myApi")
			.build();
}
 
开发者ID:ljtfreitas,项目名称:java-restify,代码行数:17,代码来源:RibbonHttpClientRequestFactoryTest.java

示例6: newHttpClient

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Override
public HttpClient<ByteBuf, ByteBuf> newHttpClient(final IClientConfig config) {
    final List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = new ArrayList<>();
    listeners.add(createBearerHeaderAdder());
    final PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator = new PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>,
            HttpClientRequest<ByteBuf>>(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(),
                                        new HttpObjectAggregationConfigurator(maxChunkSize));
    final LoadBalancingHttpClient<ByteBuf, ByteBuf> client = LoadBalancingHttpClient.<ByteBuf, ByteBuf>builder()
            .withClientConfig(config)
            .withExecutorListeners(listeners)
            .withRetryHandler(getDefaultHttpRetryHandlerWithConfig(config))
            .withPipelineConfigurator(pipelineConfigurator)
            .withPoolCleanerScheduler(RibbonTransport.poolCleanerScheduler)
            .build();

    return client;
}
 
开发者ID:wildfly-swarm,项目名称:wildfly-swarm,代码行数:18,代码来源:SecuredTransportFactory.java

示例7: newHttpClient

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Override
public HttpClient<ByteBuf, ByteBuf> newHttpClient(final IClientConfig config) {
    final List<ExecutionListener<HttpClientRequest<ByteBuf>, HttpClientResponse<ByteBuf>>> listeners = new ArrayList<>();
    listeners.add(createBearerHeaderAdder());
    final PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>> pipelineConfigurator = new PipelineConfiguratorComposite<HttpClientResponse<ByteBuf>, 
            HttpClientRequest<ByteBuf>>(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(),
            new HttpObjectAggregationConfigurator(maxChunkSize));
    final LoadBalancingHttpClient<ByteBuf, ByteBuf> client = LoadBalancingHttpClient.<ByteBuf, ByteBuf>builder()
            .withClientConfig(config)
            .withExecutorListeners(listeners)
            .withRetryHandler(getDefaultHttpRetryHandlerWithConfig(config))
            .withPipelineConfigurator(pipelineConfigurator)
            .withPoolCleanerScheduler(RibbonTransport.poolCleanerScheduler)
            .build();

    return client;
}
 
开发者ID:wildfly-swarm-archive,项目名称:ARCHIVE-wildfly-swarm,代码行数:18,代码来源:SecuredTransportFactory.java

示例8: createRequest

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Override
@SuppressWarnings("deprecation")
public ClientHttpRequest createRequest(URI originalUri, HttpMethod httpMethod) throws IOException {
    String serviceId = originalUri.getHost();
    ServiceInstance instance = loadBalancer.choose(serviceId);
    if (instance == null) {
        throw new IllegalStateException("No instances available for " + serviceId);
    }
    URI uri = loadBalancer.reconstructURI(instance, originalUri);

    IClientConfig clientConfig = clientFactory.getClientConfig(instance.getServiceId());
    RestClient client = clientFactory.getClient(instance.getServiceId(), RestClient.class);
    HttpRequest request = HttpRequest.newBuilder()
            .uri(uri)
            .verb(HttpRequest.Verb.valueOf(httpMethod.name()))
            .build();

    return new RibbonHttpRequest(request, client, clientConfig);
}
 
开发者ID:kamkie,项目名称:micro-service-example,代码行数:20,代码来源:RibbonClientHttpRequestFactory.java

示例9: getClient

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
private LoadBalancingHttpClient<ByteBuf, ByteBuf> getClient(String vip) {
    LoadBalancingHttpClient<ByteBuf, ByteBuf> client = httpClients.get(vip);
    if (client == null) {
        IClientConfig config = IClientConfig.Builder.newBuilder("prana_backend").
                withDefaultValues().
                withDeploymentContextBasedVipAddresses(vip).
                build().
                set(IClientConfigKey.Keys.MaxTotalConnections, 2000).
                set(IClientConfigKey.Keys.MaxConnectionsPerHost, 2000).
                set(IClientConfigKey.Keys.OkToRetryOnAllOperations, false).
                set(IClientConfigKey.Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());

        client = RibbonTransport.newHttpClient(new HttpClientPipelineConfigurator<ByteBuf, ByteBuf>(), config);
        httpClients.putIfAbsent(vip, client);

    }
    return client;
}
 
开发者ID:Netflix,项目名称:Prana,代码行数:19,代码来源:ProxyHandler.java

示例10: okHttpLoadBalancingClient

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
@ConditionalOnClass(name = "org.springframework.retry.support.RetryTemplate")
public RetryableOkHttpLoadBalancingClient okHttpLoadBalancingClient(
	IClientConfig config,
	ServerIntrospector serverIntrospector,
	ILoadBalancer loadBalancer,
	RetryHandler retryHandler,
	LoadBalancedRetryPolicyFactory loadBalancedRetryPolicyFactory,
	OkHttpClient delegate,
	LoadBalancedBackOffPolicyFactory loadBalancedBackOffPolicyFactory,
	LoadBalancedRetryListenerFactory loadBalancedRetryListenerFactory) {
	RetryableOkHttpLoadBalancingClient client = new RetryableOkHttpLoadBalancingClient(delegate, config,
			serverIntrospector, loadBalancedRetryPolicyFactory, loadBalancedBackOffPolicyFactory, loadBalancedRetryListenerFactory);
	client.setLoadBalancer(loadBalancer);
	client.setRetryHandler(retryHandler);
	Monitors.registerObject("Client_" + this.name, client);
	return client;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:20,代码来源:OkHttpRibbonConfiguration.java

示例11: RibbonLoadBalancedRetryPolicy

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
public RibbonLoadBalancedRetryPolicy(String serviceId, RibbonLoadBalancerContext context, ServiceInstanceChooser loadBalanceChooser,
									 IClientConfig clientConfig) {
	this.serviceId = serviceId;
	this.lbContext = context;
	this.loadBalanceChooser = loadBalanceChooser;
	String retryableStatusCodesProp = clientConfig.getPropertyAsString(RETRYABLE_STATUS_CODES, "");
	String[] retryableStatusCodesArray = retryableStatusCodesProp.split(",");
	for(String code : retryableStatusCodesArray) {
		if(!StringUtils.isEmpty(code)) {
			try {
				retryableStatusCodes.add(Integer.valueOf(code.trim()));
			} catch (NumberFormatException e) {
				log.warn("We cant add the status code because the code [ " + code + " ] could not be converted to an integer. ", e);
			}
		}
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:18,代码来源:RibbonLoadBalancedRetryPolicy.java

示例12: httpClientConnectionManager

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(HttpClientConnectionManager.class)
public HttpClientConnectionManager httpClientConnectionManager(
		IClientConfig config,
		ApacheHttpClientConnectionManagerFactory connectionManagerFactory) {
	RibbonProperties ribbon = RibbonProperties.from(config);
	int maxTotalConnections = ribbon.maxTotalConnections();
	int maxConnectionsPerHost = ribbon.maxConnectionsPerHost();
	int timerRepeat = ribbon.connectionCleanerRepeatInterval();
	long timeToLive = ribbon.poolKeepAliveTime();
	TimeUnit ttlUnit = ribbon.getPoolKeepAliveTimeUnits();
	final HttpClientConnectionManager connectionManager = connectionManagerFactory
			.newConnectionManager(false, maxTotalConnections,
					maxConnectionsPerHost, timeToLive, ttlUnit, registryBuilder);
	this.connectionManagerTimer.schedule(new TimerTask() {
		@Override
		public void run() {
			connectionManager.closeExpiredConnections();
		}
	}, 30000, timerRepeat);
	return connectionManager;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:HttpClientRibbonConfiguration.java

示例13: retryableRibbonLoadBalancingHttpClient

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(AbstractLoadBalancerAwareClient.class)
@ConditionalOnClass(name = "org.springframework.retry.support.RetryTemplate")
public RetryableRibbonLoadBalancingHttpClient retryableRibbonLoadBalancingHttpClient(
	IClientConfig config, ServerIntrospector serverIntrospector,
	ILoadBalancer loadBalancer, RetryHandler retryHandler,
	LoadBalancedRetryPolicyFactory loadBalancedRetryPolicyFactory, CloseableHttpClient httpClient,
	LoadBalancedBackOffPolicyFactory loadBalancedBackOffPolicyFactory,
	LoadBalancedRetryListenerFactory loadBalancedRetryListenerFactory) {
	RetryableRibbonLoadBalancingHttpClient client = new RetryableRibbonLoadBalancingHttpClient(
		httpClient, config, serverIntrospector, loadBalancedRetryPolicyFactory,
		loadBalancedBackOffPolicyFactory, loadBalancedRetryListenerFactory);
	client.setLoadBalancer(loadBalancer);
	client.setRetryHandler(retryHandler);
	Monitors.registerObject("Client_" + this.name, client);
	return client;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:18,代码来源:HttpClientRibbonConfiguration.java

示例14: testRetryableStatusCodes

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
@Test
public void testRetryableStatusCodes() throws Exception {
	int sameServer = 3;
	int nextServer = 3;
	RibbonServer server = getRibbonServer();
	IClientConfig config = mock(IClientConfig.class);
	doReturn(sameServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetries), anyInt());
	doReturn(nextServer).when(config).get(eq(CommonClientConfigKey.MaxAutoRetriesNextServer), anyInt());
	doReturn(false).when(config).get(eq(CommonClientConfigKey.OkToRetryOnAllOperations), eq(false));
	doReturn(config).when(clientFactory).getClientConfig(eq(server.getServiceId()));
	doReturn("404, 418,502,foo, ,").when(config).getPropertyAsString(eq(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES),eq(""));
	clientFactory.getLoadBalancerContext(server.getServiceId()).setRetryHandler(new DefaultLoadBalancerRetryHandler(config));
	RibbonLoadBalancerClient client = getRibbonLoadBalancerClient(server);
	RibbonLoadBalancedRetryPolicyFactory factory = new RibbonLoadBalancedRetryPolicyFactory(clientFactory);
	LoadBalancedRetryPolicy policy = factory.create(server.getServiceId(), client);
	HttpRequest request = mock(HttpRequest.class);
	doReturn(HttpMethod.GET).when(request).getMethod();
	assertThat(policy.retryableStatusCode(400), is(false));
	assertThat(policy.retryableStatusCode(404), is(true));
	assertThat(policy.retryableStatusCode(418), is(true));
	assertThat(policy.retryableStatusCode(502), is(true));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:RibbonLoadBalancedRetryPolicyFactoryTests.java

示例15: getSetter

import com.netflix.client.config.IClientConfig; //导入依赖的package包/类
protected static Setter getSetter(final String commandKey,
		ZuulProperties zuulProperties, IClientConfig config) {

	// @formatter:off
	Setter commandSetter = Setter.withGroupKey(HystrixCommandGroupKey.Factory.asKey("RibbonCommand"))
							.andCommandKey(HystrixCommandKey.Factory.asKey(commandKey));
	final HystrixCommandProperties.Setter setter = createSetter(config, commandKey, zuulProperties);
	if (zuulProperties.getRibbonIsolationStrategy() == ExecutionIsolationStrategy.SEMAPHORE){
		final String name = ZuulConstants.ZUUL_EUREKA + commandKey + ".semaphore.maxSemaphores";
		// we want to default to semaphore-isolation since this wraps
		// 2 others commands that are already thread isolated
		final DynamicIntProperty value = DynamicPropertyFactory.getInstance()
				.getIntProperty(name, zuulProperties.getSemaphore().getMaxSemaphores());
		setter.withExecutionIsolationSemaphoreMaxConcurrentRequests(value.get());
	} else if (zuulProperties.getThreadPool().isUseSeparateThreadPools()) {
		final String threadPoolKey = zuulProperties.getThreadPool().getThreadPoolKeyPrefix() + commandKey;
		commandSetter.andThreadPoolKey(HystrixThreadPoolKey.Factory.asKey(threadPoolKey));
	}
	
	return commandSetter.andCommandPropertiesDefaults(setter);
	// @formatter:on
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:23,代码来源:AbstractRibbonCommand.java


注:本文中的com.netflix.client.config.IClientConfig类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。