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


Java SpringClientFactory类代码示例

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


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

示例1: init

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
private void init(ApplicationContext ctx) {
	loadBalancedRestTemplate = new RestTemplate();
	SpringClientFactory springClientFactory = springClientFactory();
	springClientFactory.setApplicationContext(ctx);
	
	loadBalancerClient = new RibbonLoadBalancerClient(springClientFactory);
	
	//custom restTemplate
	LoadBalancerRequestFactory requestFactory = new LoadBalancerRequestFactory(loadBalancerClient, Collections.emptyList());
	LoadBalancerInterceptor interceptor = new LoadBalancerInterceptor(loadBalancerClient, requestFactory);
	
	List<ClientHttpRequestInterceptor> interceptors = loadBalancedRestTemplate.getInterceptors();
	ArrayList<ClientHttpRequestInterceptor> customedInterceptors = new ArrayList<>(interceptors.size() + 1);
	customedInterceptors.addAll(interceptors);
	customedInterceptors.add(interceptor);
	
	loadBalancedRestTemplate.setInterceptors(customedInterceptors);
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:19,代码来源:RestRibbonEasyTransRpcConsumerImpl.java

示例2: addTracingClient

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
private Object addTracingClient(Object bean) {
  if (bean instanceof TracingClient || bean instanceof LoadBalancedTracedFeign) {
    return bean;
  }

  if (bean instanceof Client) {
    if (bean instanceof LoadBalancerFeignClient && !(bean instanceof LoadBalancedTracedFeign)) {
      return new LoadBalancedTracedFeign(
          new TracingClient(((LoadBalancerFeignClient) bean).getDelegate(), tracer),
          beanFactory.getBean(CachingSpringLoadBalancerFactory.class),
          beanFactory.getBean(SpringClientFactory.class));
    }
    return new TracingClient((Client) bean, tracer);
  }

  return bean;
}
 
开发者ID:opentracing-contrib,项目名称:java-spring-cloud,代码行数:18,代码来源:TraceFeignContext.java

示例3: testHystrixTimeoutValueRibbonTimeouts

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
public void testHystrixTimeoutValueRibbonTimeouts() throws Exception {
	SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
	ZuulProperties zuulProperties = new ZuulProperties();
	OkHttpLoadBalancingClient loadBalancingHttpClient = mock(OkHttpLoadBalancingClient.class);
	IClientConfig clientConfig = new DefaultClientConfigImpl();
	clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
	clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
	doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(),
			eq(OkHttpLoadBalancingClient.class));
	doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
	OkHttpRibbonCommandFactory commandFactory = new OkHttpRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
	RibbonCommandContext context = mock(RibbonCommandContext.class);
	doReturn("service").when(context).getServiceId();
	OkHttpRibbonCommand ribbonCommand = commandFactory.create(context);
	assertEquals(600, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:18,代码来源:OkHttpRibbonCommandFactoryTest.java

示例4: testHystrixTimeoutValueRibbonTimeouts

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
public void testHystrixTimeoutValueRibbonTimeouts() throws Exception {
	SpringClientFactory springClientFactory = mock(SpringClientFactory.class);
	ZuulProperties zuulProperties = new ZuulProperties();
	RibbonLoadBalancingHttpClient loadBalancingHttpClient = mock(RibbonLoadBalancingHttpClient.class);
	IClientConfig clientConfig = new DefaultClientConfigImpl();
	clientConfig.set(IClientConfigKey.Keys.ConnectTimeout, 100);
	clientConfig.set(IClientConfigKey.Keys.ReadTimeout, 500);
	doReturn(loadBalancingHttpClient).when(springClientFactory).getClient(anyString(),
			eq(RibbonLoadBalancingHttpClient.class));
	doReturn(clientConfig).when(springClientFactory).getClientConfig(anyString());
	HttpClientRibbonCommandFactory ribbonCommandFactory = new HttpClientRibbonCommandFactory(springClientFactory, zuulProperties, new HashSet<FallbackProvider>());
	RibbonCommandContext context = mock(RibbonCommandContext.class);
	doReturn("service").when(context).getServiceId();
	HttpClientRibbonCommand ribbonCommand = ribbonCommandFactory.create(context);
	assertEquals(600, ribbonCommand.getProperties().executionTimeoutInMilliseconds().get().intValue());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:18,代码来源:HttpClientRibbonCommandFactoryTest.java

示例5: basicConfigurationCreatedForLoadBalancer

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
@Ignore
public void basicConfigurationCreatedForLoadBalancer() {
	EurekaClientConfigBean client = new EurekaClientConfigBean();
	EurekaInstanceConfigBean configBean = getEurekaInstanceConfigBean();
	client.getAvailabilityZones().put(client.getRegion(), "foo");
	SpringClientFactory clientFactory = new SpringClientFactory();
	EurekaRibbonClientConfiguration clientPreprocessor = new EurekaRibbonClientConfiguration(
			client, "service", configBean, false);
	clientPreprocessor.preprocess();
	ILoadBalancer balancer = clientFactory.getLoadBalancer("service");
	assertNotNull(balancer);
	@SuppressWarnings("unchecked")
	ZoneAwareLoadBalancer<DiscoveryEnabledServer> aware = (ZoneAwareLoadBalancer<DiscoveryEnabledServer>) balancer;
	assertTrue(aware.getServerListImpl() instanceof DomainExtractingServerList);
	assertEquals("foo",
			ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:19,代码来源:EurekaRibbonClientConfigurationTests.java

示例6: getRequestSpecificRetryHandler

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
public void getRequestSpecificRetryHandler() throws Exception {
	RibbonLoadBalancerContext lbContext = new RibbonLoadBalancerContext(lb, config);
	SpringClientFactory clientFactory = mock(SpringClientFactory.class);
	doReturn(lbContext).when(clientFactory).getLoadBalancerContext(any(String.class));
	RibbonLoadBalancedRetryPolicyFactory loadBalancedRetryPolicyFactory = new RibbonLoadBalancedRetryPolicyFactory(clientFactory);
	HttpRequest springRequest = mock(HttpRequest.class);
	Request feignRequest = Request.create("GET", "http://foo", new HashMap<String, Collection<String>>(),
			new byte[]{}, StandardCharsets.UTF_8);
	Client client = mock(Client.class);
	FeignLoadBalancer.RibbonRequest request = new FeignLoadBalancer.RibbonRequest(client, feignRequest, new URI("http://foo"));
	Response response = Response.builder().status(200).headers(new HashMap<String, Collection<String>>()).build();
	doReturn(response).when(client).execute(any(Request.class), any(Request.Options.class));
	RetryableFeignLoadBalancer feignLb = new RetryableFeignLoadBalancer(lb, config, inspector, loadBalancedRetryPolicyFactory,
			loadBalancedBackOffPolicyFactory);
	RequestSpecificRetryHandler retryHandler = feignLb.getRequestSpecificRetryHandler(request, config);
	assertEquals(1, retryHandler.getMaxRetriesOnNextServer());
	assertEquals(1, retryHandler.getMaxRetriesOnSameServer());

}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:21,代码来源:RetryableFeignLoadBalancerTests.java

示例7: springClientFactory

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
public SpringClientFactory springClientFactory() {
	SpringClientFactory factory = new SpringClientFactory();
	ArrayList<RibbonClientSpecification> list = new ArrayList<RibbonClientSpecification>(configurations);
	list.add(new RibbonClientSpecification("default.easytrans", new Class[]{RestEasyTransactionConfiguration.class}));
	factory.setConfigurations(list);
	return factory;
}
 
开发者ID:QNJR-GROUP,项目名称:EasyTransaction,代码行数:8,代码来源:RestRibbonEasyTransRpcConsumerImpl.java

示例8: ProxyController

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Autowired
public ProxyController(HttpProxy httpProxy, SpringClientFactory springClientFactory) {
    this.httpProxy = httpProxy;

    RibbonLoadBalancerContext context = springClientFactory.getLoadBalancerContext(SERVICEID);
    IClientConfig clientConfig = springClientFactory.getClientConfig(SERVICEID);
    ILoadBalancer loadBalancer = springClientFactory.getLoadBalancer(SERVICEID);
    HttpClientLoadBalancerErrorHandler requestSpecificRetryHandler = getRequestSpecificRetryHandler(clientConfig);

    this.commandBuilder = LoadBalancerCommand.builder()
            .withRetryHandler(requestSpecificRetryHandler)
            .withLoadBalancerContext(context)
            .withClientConfig(clientConfig)
            .withLoadBalancer(loadBalancer);
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:16,代码来源:ProxyController.java

示例9: TraceRestClientRibbonCommandFactory

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
public TraceRestClientRibbonCommandFactory(SpringClientFactory clientFactory,
		Tracer tracer, SpanInjector<HttpRequest.Builder> spanInjector,
		HttpTraceKeysInjector httpTraceKeysInjector) {
	super(clientFactory);
	this.tracer = tracer;
	this.spanInjector = spanInjector;
	this.httpTraceKeysInjector = httpTraceKeysInjector;
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:9,代码来源:TraceRestClientRibbonCommandFactory.java

示例10: clientFactory

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
private SpringClientFactory clientFactory() {
	if (this.springClientFactory == null) {
		this.springClientFactory = this.beanFactory
				.getBean(SpringClientFactory.class);
	}
	return this.springClientFactory;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:8,代码来源:TraceFeignObjectWrapper.java

示例11: testUpdatedTimeouts

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
public void testUpdatedTimeouts() throws Exception {
	SpringClientFactory factory = new SpringClientFactory();
	OkHttpClient result = getHttpClient(Timeouts.class, null, factory);
	assertThat(result.readTimeoutMillis(), is(50000));
	assertThat(result.connectTimeoutMillis(), is(60000));
	IClientConfig config = factory.getClientConfig("service");
	config.set(CommonClientConfigKey.ConnectTimeout, 60);
	config.set(CommonClientConfigKey.ReadTimeout, 50);
	result = getHttpClient(Timeouts.class, null, factory);
	assertThat(result.readTimeoutMillis(), is(50));
	assertThat(result.connectTimeoutMillis(), is(60));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:14,代码来源:OkHttpLoadBalancingClientTests.java

示例12: getHttpClient

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
private OkHttpClient getHttpClient(Class<?> defaultConfigurationClass,
								   IClientConfig configOverride,
								   SpringClientFactory factory) throws Exception {
	factory.setApplicationContext(new AnnotationConfigApplicationContext(
			RibbonAutoConfiguration.class, OkHttpClientConfiguration.class, defaultConfigurationClass));

	OkHttpLoadBalancingClient client = factory.getClient("service",
			OkHttpLoadBalancingClient.class);

	return client.getOkHttpClient(configOverride, false);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:12,代码来源:OkHttpLoadBalancingClientTests.java

示例13: testConnections

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
public void testConnections() throws Exception {
	SpringClientFactory factory = new SpringClientFactory();
	factory.setApplicationContext(new AnnotationConfigApplicationContext(
			RibbonAutoConfiguration.class, Connections.class));
	RetryableRibbonLoadBalancingHttpClient client = factory.getClient("service",
			RetryableRibbonLoadBalancingHttpClient.class);

	HttpClient delegate = client.getDelegate();
	PoolingHttpClientConnectionManager connManager = (PoolingHttpClientConnectionManager) ReflectionTestUtils.getField(delegate, "connManager");
	assertThat(connManager.getMaxTotal(), is(101));
	assertThat(connManager.getDefaultMaxPerRoute(), is(201));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:14,代码来源:RibbonLoadBalancingHttpClientTests.java

示例14: testUpdatedTimeouts

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
@Test
public void testUpdatedTimeouts()
		throws Exception {
	SpringClientFactory factory = new SpringClientFactory();
	RequestConfig result = getBuiltRequestConfig(Timeouts.class, null, factory);
	assertThat(result.getConnectTimeout(), is(60000));
	assertThat(result.getSocketTimeout(), is (50000));
	IClientConfig config = factory.getClientConfig("service");
	config.set(CommonClientConfigKey.ConnectTimeout, 60);
	config.set(CommonClientConfigKey.ReadTimeout, 50);
	result = getBuiltRequestConfig(Timeouts.class, null, factory);
	assertThat(result.getConnectTimeout(), is(60));
	assertThat(result.getSocketTimeout(), is (50));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:15,代码来源:RibbonLoadBalancingHttpClientTests.java

示例15: setupClientForRetry

import org.springframework.cloud.netflix.ribbon.SpringClientFactory; //导入依赖的package包/类
private RetryableRibbonLoadBalancingHttpClient setupClientForRetry(int retriesNextServer, int retriesSameServer,
																   boolean retryable, boolean retryOnAllOps,
																   String serviceName, String host, int port,
																   CloseableHttpClient delegate, ILoadBalancer lb, String statusCodes,
																   LoadBalancedBackOffPolicyFactory loadBalancedBackOffPolicyFactory,
																   boolean isSecure) throws Exception {
	ServerIntrospector introspector = mock(ServerIntrospector.class);
	RetryHandler retryHandler = new DefaultLoadBalancerRetryHandler(retriesSameServer, retriesNextServer, retryable);
	doReturn(new Server(host, port)).when(lb).chooseServer(eq(serviceName));
	DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
	clientConfig.set(CommonClientConfigKey.OkToRetryOnAllOperations, retryOnAllOps);
	clientConfig.set(CommonClientConfigKey.MaxAutoRetriesNextServer, retriesNextServer);
	clientConfig.set(CommonClientConfigKey.MaxAutoRetries, retriesSameServer);
	clientConfig.set(RibbonLoadBalancedRetryPolicy.RETRYABLE_STATUS_CODES, statusCodes);
	clientConfig.set(CommonClientConfigKey.IsSecure, isSecure);
	clientConfig.setClientName(serviceName);
	RibbonLoadBalancerContext context = new RibbonLoadBalancerContext(lb, clientConfig, retryHandler);
	SpringClientFactory clientFactory = mock(SpringClientFactory.class);
	doReturn(context).when(clientFactory).getLoadBalancerContext(eq(serviceName));
	doReturn(clientConfig).when(clientFactory).getClientConfig(eq(serviceName));
	LoadBalancedRetryPolicyFactory factory = new RibbonLoadBalancedRetryPolicyFactory(clientFactory);
	RetryableRibbonLoadBalancingHttpClient client = new RetryableRibbonLoadBalancingHttpClient(delegate, clientConfig,
			introspector, factory, loadBalancedBackOffPolicyFactory);
	client.setLoadBalancer(lb);
	ReflectionTestUtils.setField(client, "delegate", delegate);
	return client;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:28,代码来源:RibbonLoadBalancingHttpClientTests.java


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