Custom Discovery client registration does supply the instances
How can we make a ServiceInstanceListSupplier that is dynamic and able to provide a service instance list based on service id.
The simple discovery client is static but it allows adding different services and instances. I have tested this to work locally. The correct service id is used to pick an instance in round robin fashion.
But when I exclude - SimpleDiscoveryClient and add my own implementation following the exact same code but instances fetched from a repo it fails to identify the service id and picks wrong instance.
Any guidance and help will be appreciated.
Describe the scenario in more details - not using Eureka but custom registry which can be queried using SDK.
a. Spring Cloud Gateway - calling couple of downstream services - so would need the ability to get this dynamic instance list from the custom registry.
b. The downstream services communicate with each other - requires the use of Spring Cloud Load balancer with Spring Cloud OpenFeign.
@Component
@Slf4j
public class DefaultServiceDiscoveryClient implements DiscoveryClient {
public DefaultServiceDiscoveryClient() {
log.info("** Default service discovery client created");
}
@Override
public String description() {
return "Default Service Discovery Client";
}
@Override
public List<ServiceInstance> getInstances(String serviceId) {
log.info("Service id : {}", serviceId);
//just hard coded sample list to test locally
return Arrays
.asList(
new DefaultServiceInstance( "0", "account", "localhost", 7081, false),
new DefaultServiceInstance( "1", "account", "localhost", 7080, false));
}
@Override
public List<String> getServices() {
log.info("=== getServices ----");
return Arrays.asList("account", "customer"); //never called except command line runner
}
public int getOrder() {
return Ordered.HIGHEST_PRECEDENCE;
}
}
@Slf4j
@Component
@RequiredArgsConstructor
public class CheckDiscoveryCommandLineRunner implements CommandLineRunner {
private final CompositeDiscoveryClient compositeDiscoveryClient;
@Override
public void run(String... args) throws Exception {
//serviceRegistry.register(new CloudMapRegistration("account","0", "http", "localhost", 7081));
log.info("composite - {}", compositeDiscoveryClient.getDiscoveryClients());
log.info("services - {}", compositeDiscoveryClient.getServices());
log.info("instances - {}", compositeDiscoveryClient.getInstances("account"));
}
}
Logs From command line runner
composite - [com.xyz.gateway.tbd.DefaultServiceDiscoveryClient@743c3520] ... services - [account, customer]
Service id : account
instances - [DefaultServiceInstance{instanceId='0', serviceId='account', host='localhost', port=7081, secure=false, metadata={}}, DefaultServiceInstance{instanceId='1', serviceId='account', host='localhost', port=7080, secure=false, metadata={}}]
- Versions * Spring Boot 2.6.3 Spring Cloud Load Balancer - 3.1.1 Spring Cloud Gateway - 3.1.1
Hello, @kdhrubo. Please provide a minimal, complete, verifiable example that reproduces the issue - will verify it for you.
I can upload it on Github ? will that work? However to run you will need AWS services.
I will try to summarize the problem if that helps and what i am looking for
I need a way use AWS Cloudmap service discovery. In other words - I do not or cannot use Eureka.
So please help in create a ServiceListInstanceSupplier and DiscoveryClient that connects to Cloudmap to retrieve the actual IPs for the services. At this moment I created both but not able to correctly configure it and Instance list supplier or discovery client is not called by Load balancer component. Please help get a sample to configure a custom Instancelist supplier and discovery client. Similar to simple but not hard coded. I need to know how these beens are configured like it is done for Eureka.
Hope this helps.
Hello, @kdhrubo - I need to see a code demo to be able to see your implementation and how you are plugging it in. Please provide a minimal, complete, verifiable example that reproduces the issue.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
I will get you the code on GitHub this weekend.
On Wed, Apr 13, 2022, 4:05 AM Spring Cloud Issues @.***> wrote:
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
— Reply to this email directly, view it on GitHub https://github.com/spring-cloud/spring-cloud-commons/issues/1081#issuecomment-1097752785, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAISPRGFV7VWKWFCDHGNUXDVE2E3XANCNFSM5RJLU24A . You are receiving this because you were mentioned.Message ID: @.***>
Ok, please do.
@OlgaMaciaszek busy at work. Please feel free to close this ticket. I will raise a new one with code. Sorry for the delay.
Ok. No problem. Please do when you have some time.