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

The following examples show how to use org.springframework.cloud.client.loadbalancer.reactive.Request. 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: LoadBalancerTests.java    From spring-cloud-commons with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@Test
public void canPassHintViaRequest() {
	String serviceId = "test1";
	RoundRobinLoadBalancer loadBalancer = new TestHintLoadBalancer(
			ServiceInstanceListSuppliers.toProvider(serviceId,
					instance(serviceId, "1host", false),
					instance(serviceId, "2host-secure", true)),
			serviceId);
	Request<DefaultRequestContext> request = new DefaultRequest<>(
			new DefaultRequestContext("test2"));

	ServiceInstance serviceInstance = loadBalancer.choose(request).block()
			.getServer();

	assertThat(serviceInstance.getServiceId()).isEqualTo("test2");
}
 
Example #2
Source File: ConsumerSCLBApplication.java    From spring-cloud-alibaba with Apache License 2.0 5 votes vote down vote up
@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 #3
Source File: RoundRobinLoadBalancer.java    From spring-cloud-commons with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
// see original
// https://github.com/Netflix/ocelli/blob/master/ocelli-core/
// src/main/java/netflix/ocelli/loadbalancer/RoundRobinLoadBalancer.java
public Mono<Response<ServiceInstance>> choose(Request request) {
	ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider
			.getIfAvailable(NoopServiceInstanceListSupplier::new);
	return supplier.get().next().map(this::getInstanceResponse);
}
 
Example #4
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 #5
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 #6
Source File: BlockingLoadBalancerClientTests.java    From spring-cloud-commons with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<Response<ServiceInstance>> choose(Request request) {
	return choose();
}
 
Example #7
Source File: ReactorLoadBalancer.java    From spring-cloud-commons with Apache License 2.0 2 votes vote down vote up
/**
 * Choose the next server based on the load balancing algorithm.
 * @param request - an input request
 * @return - mono of response
 */
@SuppressWarnings("rawtypes")
Mono<Response<T>> choose(Request request);