Skip to content

Instantly share code, notes, and snippets.

@gauravat16
Created May 30, 2020 18:01
Show Gist options
  • Save gauravat16/dc538749263dd74fe2f4ac7937eab267 to your computer and use it in GitHub Desktop.
Save gauravat16/dc538749263dd74fe2f4ac7937eab267 to your computer and use it in GitHub Desktop.
@Configuration
@RibbonClient(name = "payment-gateway", configuration = PaymentGatewayConfiguration.class)
public class PaymentGatewayConfiguration {
@Bean
public IPing ribbonPing(IClientConfig config) {
return new PingUrl();
}
@Bean
public IRule ribbonRule(IClientConfig config) {
return new RandomRule();
}
@Bean
public ServerList<Server> getServerList() {
return new ServerList<Server>() {
@Override
public List<Server> getInitialListOfServers() {
return new ArrayList<>();
}
@Override
public List<Server> getUpdatedListOfServers() {
int totalServers = 10;
List<Server> serverList = new ArrayList<>();
for (Server server : gatewayConfig.getGatewayURLMap().values()) {
if (server instanceof GatewayServer) {
int count = (int) (((GatewayServer) server).getRatio() * totalServers);
while (count-- > 0 && serverList.size() < totalServers) {
serverList.add(server);
}
}
}
return serverList;
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment