org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer Java Examples

The following examples show how to use org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalancer. 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: BlockingLoadBalancerClient.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceInstance choose(String serviceId) {
	ReactiveLoadBalancer<ServiceInstance> loadBalancer = loadBalancerClientFactory
			.getInstance(serviceId);
	if (loadBalancer == null) {
		return null;
	}
	Response<ServiceInstance> loadBalancerResponse = Mono.from(loadBalancer.choose())
			.block();
	if (loadBalancerResponse == null) {
		return null;
	}
	return loadBalancerResponse.getServer();
}
 
Example #2
Source File: LoadBalancerTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Test
public void roundRobbinLoadbalancerWorks() {
	ReactiveLoadBalancer<ServiceInstance> reactiveLoadBalancer = this.clientFactory
			.getInstance("myservice", ReactiveLoadBalancer.class,
					ServiceInstance.class);

	then(reactiveLoadBalancer).isInstanceOf(RoundRobinLoadBalancer.class);
	then(reactiveLoadBalancer).isInstanceOf(ReactorLoadBalancer.class);
	ReactorLoadBalancer<ServiceInstance> loadBalancer = (ReactorLoadBalancer<ServiceInstance>) reactiveLoadBalancer;

	// order dependent on seedPosition -1 of RoundRobinLoadBalancer
	List<String> hosts = Arrays.asList("ahost", "chost", "bhostsecure", "ahost");

	assertLoadBalancer(loadBalancer, hosts);
}
 
Example #3
Source File: SpringCloudLoadBalancerAutoConfiguration.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@Override
public ReactiveLoadBalancer<ServiceInstance> getInstance(String serviceId) {
	return (ReactorServiceInstanceLoadBalancer) request -> Mono
			.just(new DefaultResponse(new StubbedServiceInstance(stubFinder(),
					stubMapperProperties(), serviceId)));
}
 
Example #4
Source File: ReactiveLoadBalancerClientFilter.java    From spring-cloud-gateway with Apache License 2.0 4 votes vote down vote up
private Request createRequest() {
	return ReactiveLoadBalancer.REQUEST;
}
 
Example #5
Source File: LoadBalancerClientFactory.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
public ReactiveLoadBalancer<ServiceInstance> getInstance(String serviceId) {
	return getInstance(serviceId, ReactorServiceInstanceLoadBalancer.class);
}
 
Example #6
Source File: ReactiveCommonsClientAutoConfiguration.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Bean
public HasFeatures reactiveCommonsFeatures() {
	return HasFeatures.abstractFeatures(ReactiveDiscoveryClient.class,
			ReactiveLoadBalancer.class);
}