本文整理汇总了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);
}
示例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;
}
示例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());
}
示例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());
}
示例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));
}
示例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());
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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));
}
示例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));
}
示例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;
}