Skip to content

Instantly share code, notes, and snippets.

@omidp
Created October 15, 2021 04:53
Show Gist options
  • Save omidp/59dcae0f0a1f0299e77b892da9b27040 to your computer and use it in GitHub Desktop.
Save omidp/59dcae0f0a1f0299e77b892da9b27040 to your computer and use it in GitHub Desktop.
instance router
System.out.println(env);
List<InstanceInfo> instanceList = dc.getApplication("USER-SERVICE").getInstances().stream().filter(f->{
return f.getMetadata() != null && env.equals(f.getMetadata().get("env"));
}).collect(Collectors.toList());
int randomElementIndex
= ThreadLocalRandom.current().nextInt(instanceList.size()) % instanceList.size();
InstanceInfo instanceInfo = instanceList.get(randomElementIndex);
System.out.println(instanceInfo.getHomePageUrl());
#################################
eureka:
client:
service-url:
defaultZone: http://omidp:8761/eureka/
instance:
metadata-map:
env: sit
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
spring:
application:
name: user-service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment