org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier Java Examples
The following examples show how to use
org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ZookeeperLoadBalancerConfiguration.java From spring-cloud-zookeeper with Apache License 2.0 | 6 votes |
@Bean @ConditionalOnBean(DiscoveryClient.class) @ConditionalOnMissingBean public ServiceInstanceListSupplier zookeeperDiscoveryClientServiceInstanceListSupplier( DiscoveryClient discoveryClient, Environment env, ApplicationContext context, ZookeeperDependencies zookeeperDependencies) { DiscoveryClientServiceInstanceListSupplier firstDelegate = new DiscoveryClientServiceInstanceListSupplier( discoveryClient, env); ZookeeperServiceInstanceListSupplier secondDelegate = new ZookeeperServiceInstanceListSupplier(firstDelegate, zookeeperDependencies); ObjectProvider<LoadBalancerCacheManager> cacheManagerProvider = context .getBeanProvider(LoadBalancerCacheManager.class); if (cacheManagerProvider.getIfAvailable() != null) { return new CachingServiceInstanceListSupplier(secondDelegate, cacheManagerProvider.getIfAvailable()); } return secondDelegate; }
Example #2
Source File: LoadBalancerClientConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Test void shouldInstantiateHealthCheckServiceInstanceListSupplier() { reactiveDiscoveryClientRunner.withUserConfiguration(TestConfig.class) .withPropertyValues( "spring.cloud.loadbalancer.configurations=health-check") .run(context -> { ServiceInstanceListSupplier supplier = context .getBean(ServiceInstanceListSupplier.class); then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier) .getDelegate(); then(delegate) .isInstanceOf(HealthCheckServiceInstanceListSupplier.class); ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate) .getDelegate(); then(secondDelegate).isInstanceOf( DiscoveryClientServiceInstanceListSupplier.class); }); }
Example #3
Source File: LoadBalancerClientConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 6 votes |
@Test void shouldInstantiateZonePreferenceServiceInstanceListSupplier() { reactiveDiscoveryClientRunner .withPropertyValues( "spring.cloud.loadbalancer.configurations=zone-preference") .run(context -> { ServiceInstanceListSupplier supplier = context .getBean(ServiceInstanceListSupplier.class); then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); ServiceInstanceListSupplier delegate = ((DelegatingServiceInstanceListSupplier) supplier) .getDelegate(); then(delegate).isInstanceOf( ZonePreferenceServiceInstanceListSupplier.class); ServiceInstanceListSupplier secondDelegate = ((DelegatingServiceInstanceListSupplier) delegate) .getDelegate(); then(secondDelegate).isInstanceOf( DiscoveryClientServiceInstanceListSupplier.class); }); }
Example #4
Source File: LoadBalancerClientConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test void shouldInstantiateDefaultBlockingServiceInstanceListSupplier() { blockingDiscoveryClientRunner .withPropertyValues("spring.cloud.loadbalancer.configurations=default") .run(context -> { ServiceInstanceListSupplier supplier = context .getBean(ServiceInstanceListSupplier.class); then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate()) .isInstanceOf( DiscoveryClientServiceInstanceListSupplier.class); }); }
Example #5
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer( Environment environment, LoadBalancerClientFactory loadBalancerClientFactory) { String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME); return new RoundRobinLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name); }
Example #6
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean(ReactiveDiscoveryClient.class) @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "default", matchIfMissing = true) public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder().withDiscoveryClient() .withCaching().build(context); }
Example #7
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean(ReactiveDiscoveryClient.class) @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-preference") public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder().withDiscoveryClient() .withZonePreference().withCaching().build(context); }
Example #8
Source File: RetryGatewayFilterFactoryIntegrationTests.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env) .instance(new DefaultServiceInstance("doesnotexist1", "badservice2", "localhost.domain.doesnot.exist", port, true)) .instance(port, "badservice2").build(); }
Example #9
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean(ReactiveDiscoveryClient.class) @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "health-check") public ServiceInstanceListSupplier healthCheckDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder().withDiscoveryClient() .withHealthChecks().withCaching().build(context); }
Example #10
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean(DiscoveryClient.class) @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "default", matchIfMissing = true) public ServiceInstanceListSupplier discoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient() .withCaching().build(context); }
Example #11
Source File: ConsumerSCLBApplication.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Override public Mono<Response<ServiceInstance>> choose(Request request) { log.info("random spring cloud loadbalacer active -.-"); ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider .getIfAvailable(NoopServiceInstanceListSupplier::new); return supplier.get().next().map(this::getInstanceResponse); }
Example #12
Source File: ConsumerSCLBApplication.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
RandomLoadBalancer( ObjectProvider<ServiceInstanceListSupplier> serviceInstanceListSupplierProvider, String serviceId) { this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider; this.serviceId = serviceId; this.random = new Random(); }
Example #13
Source File: MyLoadBalancerConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnMissingBean public ReactorLoadBalancer<ServiceInstance> reactorServiceInstanceLoadBalancer( Environment environment, LoadBalancerClientFactory loadBalancerClientFactory) { String name = environment.getProperty(LoadBalancerClientFactory.PROPERTY_NAME); return new RandomLoadBalancer(loadBalancerClientFactory.getLazyProvider(name, ServiceInstanceListSupplier.class), name); }
Example #14
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean(DiscoveryClient.class) @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-preference") public ServiceInstanceListSupplier zonePreferenceDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient() .withZonePreference().withCaching().build(context); }
Example #15
Source File: LoadBalancerClientConfiguration.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnBean(DiscoveryClient.class) @ConditionalOnMissingBean @ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "health-check") public ServiceInstanceListSupplier healthCheckDiscoveryClientServiceInstanceListSupplier( ConfigurableApplicationContext context) { return ServiceInstanceListSupplier.builder().withBlockingDiscoveryClient() .withHealthChecks().withCaching().build(context); }
Example #16
Source File: ServiceInstanceListSuppliers.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
public static ServiceInstanceListSupplier from(String serviceId, ServiceInstance... instances) { return new ServiceInstanceListSupplier() { @Override public Flux<List<ServiceInstance>> get() { return Flux.just(Arrays.asList(instances)); } @Override public String getServiceId() { return serviceId; } }; }
Example #17
Source File: LoadBalancerClientConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test void shouldInstantiateDefaultServiceInstanceListSupplierWhenConfigurationsPropertyNotSet() { reactiveDiscoveryClientRunner.run(context -> { ServiceInstanceListSupplier supplier = context .getBean(ServiceInstanceListSupplier.class); then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate()) .isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class); }); }
Example #18
Source File: LoadBalancerClientConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test void shouldInstantiateDefaultServiceInstanceListSupplier() { reactiveDiscoveryClientRunner .withPropertyValues("spring.cloud.loadbalancer.configurations=default") .run(context -> { ServiceInstanceListSupplier supplier = context .getBean(ServiceInstanceListSupplier.class); then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate()) .isInstanceOf( DiscoveryClientServiceInstanceListSupplier.class); }); }
Example #19
Source File: LoadBalancerClientConfigurationTests.java From spring-cloud-commons with Apache License 2.0 | 5 votes |
@Test void shouldInstantiateDefaultBlockingServiceInstanceListSupplierWhenConfigurationsPropertyNotSet() { blockingDiscoveryClientRunner.run(context -> { ServiceInstanceListSupplier supplier = context .getBean(ServiceInstanceListSupplier.class); then(supplier).isInstanceOf(CachingServiceInstanceListSupplier.class); then(((DelegatingServiceInstanceListSupplier) supplier).getDelegate()) .isInstanceOf(DiscoveryClientServiceInstanceListSupplier.class); }); }
Example #20
Source File: ServiceInstanceListSuppliers.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
public static ObjectProvider<ServiceInstanceListSupplier> toProvider(String serviceId, ServiceInstance... instances) { return new SimpleObjectProvider<>(from(serviceId, instances)); }
Example #21
Source File: WebClientDiscoveryExceptionTests.java From spring-cloud-sleuth with Apache License 2.0 | 4 votes |
@Bean ServiceInstanceListSupplier serviceInstanceListSupplier() { return new ServiceInstanceListSupplier() { @Override public String getServiceId() { return "exceptionservice"; } @Override public Flux<List<ServiceInstance>> get() { return Flux.just(Collections.singletonList(new ServiceInstance() { @Override public String getServiceId() { return "exceptionservice"; } @Override public String getHost() { return "localhost"; } @Override public int getPort() { return 1234; } @Override public boolean isSecure() { return false; } @Override public URI getUri() { return null; } @Override public Map<String, String> getMetadata() { return null; } })); } }; }
Example #22
Source File: ZookeeperServiceInstanceListSupplier.java From spring-cloud-zookeeper with Apache License 2.0 | 4 votes |
public ZookeeperServiceInstanceListSupplier(ServiceInstanceListSupplier delegate, ZookeeperDependencies zookeeperDependencies) { this.delegate = delegate; this.serviceId = getServiceIdFromDepsOrClientName(delegate .getServiceId(), zookeeperDependencies); }
Example #23
Source File: WebClientRetrofitLoadBalancerTests.java From spring-cloud-square with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "local").build(); }
Example #24
Source File: FeignAcceptEncodingTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "local").build(); }
Example #25
Source File: FeignClientScanningTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "local").build(); }
Example #26
Source File: FeignClientEnvVarTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "localapp") .build(); }
Example #27
Source File: FeignHttpClientTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "local").build(); }
Example #28
Source File: FeignOkHttpTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "local").build(); }
Example #29
Source File: ValidFeignClientTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "local").build(); }
Example #30
Source File: IterableParameterTests.java From spring-cloud-openfeign with Apache License 2.0 | 4 votes |
@Bean public ServiceInstanceListSupplier staticServiceInstanceListSupplier( Environment env) { return ServiceInstanceListSupplier.fixed(env).instance(port, "localapp") .build(); }