Skip to content

Make DelegatingServiceInstanceListSupplier implement SelectedInstanceCallback #1221

@HJK181

Description

@HJK181

I've tried to setup a custom load balancer as described in this post. However, with spring-cloud-starter-loadbalancer:3.1.4 I'm experiencing

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier' available: more than one 'primary' bean found among candidates: [CustomServiceInstanceListSupplier, retryAwareDiscoveryClientServiceInstanceListSupplier]
@Configuration
@LoadBalancerClient(value = "custom", configuration = CustomLoadBalancerConfiguration.class)
public class CustomLoadBalancerClient {
}

public class CustomLoadBalancerConfiguration {

	@Bean
	@Primary
	public ServiceInstanceListSupplier customServiceInstanceListSupplier(ConfigurableApplicationContext context, RedissonClient redissonClient) {
		ServiceInstanceListSupplier delegate = ServiceInstanceListSupplier.builder()
				.withDiscoveryClient()
				.withCaching()
				.build(context);
		return new CustomServiceInstanceListSupplier(delegate, redissonClient);
	}
}

public class CustomServiceInstanceListSupplier extends DelegatingServiceInstanceListSupplier implements SelectedInstanceCallback {
...
}

When deploying the application to Kubernetes along spring-cloud-kubernetes-facric8-loadbalancer:2.1.4 and activating spring.cloud.kubernetes.loadbalancer.mode=SERVICE it's even getting worse

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier' available: more than one 'primary' bean found among candidates: [customServiceInstanceListSupplier, kubernetesServicesListSupplier, retryAwareDiscoveryClientServiceInstanceListSupplier]

Am I doing something wrong, or is the example from the post wrong?

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions