org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer Java Examples
The following examples show how to use
org.springframework.cloud.loadbalancer.core.ReactorLoadBalancer.
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: ReactiveLoadBalancerClientFilterTests.java From spring-cloud-gateway with Apache License 2.0 | 6 votes |
@Test public void shouldThrow4O4ExceptionWhenNoServiceInstanceIsFound() { URI uri = UriComponentsBuilder.fromUriString("lb://service1").build().toUri(); exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, uri); RoundRobinLoadBalancer loadBalancer = new RoundRobinLoadBalancer( ServiceInstanceListSuppliers.toProvider("service1"), "service1", -1); when(clientFactory.getInstance("service1", ReactorLoadBalancer.class, ServiceInstance.class)).thenReturn(loadBalancer); properties.setUse404(true); ReactiveLoadBalancerClientFilter filter = new ReactiveLoadBalancerClientFilter( clientFactory, properties); when(chain.filter(exchange)).thenReturn(Mono.empty()); try { filter.filter(exchange, chain).block(); } catch (NotFoundException exception) { assertThat(exception.getStatus()).isEqualTo(HttpStatus.NOT_FOUND); } }
Example #2
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 #3
Source File: ReactiveLoadBalancerClientFilter.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
private Mono<Response<ServiceInstance>> choose(ServerWebExchange exchange) { URI uri = exchange.getAttribute(GATEWAY_REQUEST_URL_ATTR); ReactorLoadBalancer<ServiceInstance> loadBalancer = this.clientFactory .getInstance(uri.getHost(), ReactorLoadBalancer.class, ServiceInstance.class); if (loadBalancer == null) { throw new NotFoundException("No loadbalancer available for " + uri.getHost()); } return loadBalancer.choose(createRequest()); }
Example #4
Source File: ReactiveLoadBalancerClientFilterTests.java From spring-cloud-gateway with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void shouldFilter() { URI url = UriComponentsBuilder.fromUriString("lb://myservice").build().toUri(); exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, url); ServiceInstance serviceInstance = new DefaultServiceInstance("myservice1", "myservice", "localhost", 8080, true); RoundRobinLoadBalancer loadBalancer = new RoundRobinLoadBalancer( ServiceInstanceListSuppliers.toProvider("myservice", serviceInstance), "myservice", -1); when(clientFactory.getInstance("myservice", ReactorLoadBalancer.class, ServiceInstance.class)).thenReturn(loadBalancer); when(chain.filter(exchange)).thenReturn(Mono.empty()); filter.filter(exchange, chain).block(); assertThat((LinkedHashSet<URI>) exchange .getAttribute(GATEWAY_ORIGINAL_REQUEST_URL_ATTR)).contains(url); verify(clientFactory).getInstance("myservice", ReactorLoadBalancer.class, ServiceInstance.class); verifyNoMoreInteractions(clientFactory); assertThat((URI) exchange.getAttribute(GATEWAY_REQUEST_URL_ATTR)) .isEqualTo(URI.create("https://localhost:8080/mypath")); verify(chain).filter(exchange); verifyNoMoreInteractions(chain); }
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: BlockingLoadBalancerClientTests.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
@Bean ReactorLoadBalancer<ServiceInstance> reactiveLoadBalancer( DiscoveryClient discoveryClient) { return new DiscoveryClientBasedReactiveLoadBalancer("myservice", discoveryClient); }
Example #7
Source File: BlockingLoadBalancerClientTests.java From spring-cloud-commons with Apache License 2.0 | 4 votes |
@Bean ReactorLoadBalancer<ServiceInstance> reactiveLoadBalancer( DiscoveryClient discoveryClient) { return new DiscoveryClientBasedReactiveLoadBalancer("unknownservice", discoveryClient); }