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

The following examples show how to use org.springframework.cloud.client.loadbalancer.reactive.DefaultResponse. 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: ConsumerSCLBApplication.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
private Response<ServiceInstance> getInstanceResponse(
		List<ServiceInstance> instances) {
	if (instances.isEmpty()) {
		return new EmptyResponse();
	}
	ServiceInstance instance = instances.get(random.nextInt(instances.size()));

	return new DefaultResponse(instance);
}
 
Example #2
Source File: RoundRobinLoadBalancer.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
private Response<ServiceInstance> getInstanceResponse(
		List<ServiceInstance> instances) {
	if (instances.isEmpty()) {
		log.warn("No servers available for service: " + this.serviceId);
		return new EmptyResponse();
	}
	// TODO: enforce order?
	int pos = Math.abs(this.position.incrementAndGet());

	ServiceInstance instance = instances.get(pos % instances.size());

	return new DefaultResponse(instance);
}
 
Example #3
Source File: LoadBalancerTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
public Mono<Response<ServiceInstance>> choose(Request request) {
	if (request.getContext() instanceof DefaultRequestContext) {
		DefaultRequestContext requestContext = (DefaultRequestContext) request
				.getContext();
		return Mono.just(new DefaultResponse(
				instance(requestContext.getHint(), "host", false)));
	}
	return Mono.empty();
}
 
Example #4
Source File: BlockingLoadBalancerClientTests.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<Response<ServiceInstance>> choose() {
	List<ServiceInstance> instances = discoveryClient.getInstances(serviceId);
	if (instances.size() == 0) {
		return Mono.just(new EmptyResponse());
	}
	int instanceIdx = this.random.nextInt(instances.size());
	return Mono.just(new DefaultResponse(instances.get(instanceIdx)));
}
 
Example #5
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)));
}